From cd01c00d611008a785becf9ec0945896f49282a3 Mon Sep 17 00:00:00 2001 From: 37b7 Date: Tue, 20 May 2025 14:42:12 +0200 Subject: [PATCH] all from ai here --- middleware/redirect.ts | 11 +++++++++++ nuxt.config.ts | 7 +++++++ plugins/router.ts | 30 +++++++++++++++--------------- 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 middleware/redirect.ts 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