diff --git a/middleware/redirect.ts b/middleware/redirect.ts new file mode 100644 index 0000000..83c7cfe --- /dev/null +++ b/middleware/redirect.ts @@ -0,0 +1,11 @@ +export default defineNuxtRouteMiddleware((to, from) => { + const basePath = '/containers/matheothierry-portfolio_nuxt' + + // Si nous sommes déjà sur le bon chemin, ne rien faire + if (to.fullPath.startsWith(basePath)) { + return + } + + // Sinon, rediriger vers le bon chemin + return navigateTo(basePath + to.fullPath, { redirectCode: 301 }) +}) \ No newline at end of file diff --git a/nuxt.config.ts b/nuxt.config.ts index c5d328e..cad0c80 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -43,6 +43,13 @@ export default defineNuxtConfig({ router: { options: { strict: false + }, + middleware: ['redirect'] + }, + + nitro: { + routeRules: { + '/**': { cors: true } } }, diff --git a/plugins/router.ts b/plugins/router.ts index fe21aa2..e99402e 100644 --- a/plugins/router.ts +++ b/plugins/router.ts @@ -1,17 +1,17 @@ -export default defineNuxtPlugin({ - name: 'router', - enforce: 'pre', - setup(nuxtApp) { - nuxtApp.vueApp.config.errorHandler = (error, instance, info) => { - console.error('Vue Error:', error) - console.error('Component:', instance) - console.error('Info:', info) - } +export default defineNuxtPlugin((nuxtApp) => { + const router = useRouter() + const route = useRoute() - nuxtApp.hook('vue:error', (error, instance, info) => { - console.error('Vue Error:', error) - console.error('Component:', instance) - console.error('Info:', info) - }) - } + // Empêcher la redirection vers la racine + router.beforeEach((to, from, next) => { + const basePath = '/containers/matheothierry-portfolio_nuxt' + + // Si l'URL ne commence pas par le bon chemin, rediriger vers le bon chemin + if (!to.fullPath.startsWith(basePath)) { + next(basePath + to.fullPath) + return + } + + next() + }) }) \ No newline at end of file