Skip to content

Commit

Permalink
fix: check if route is defined by i18n before redirect (#1902)
Browse files Browse the repository at this point in the history
Co-authored-by: khaled.borghol <[email protected]>
  • Loading branch information
borghol and khaled.borghol committed Mar 3, 2023
1 parent 029c634 commit 182098b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/runtime/utils.ts
Expand Up @@ -292,6 +292,10 @@ export function detectRedirect<Context extends NuxtApp = NuxtApp>(
let redirectPath = ''
const isStaticGenerate = isSSG && process.server

if (!isI18nRouteDefined(route)) {
return redirectPath
}

// decide whether we should redirect to a different route.
if (
!isStaticGenerate &&
Expand Down Expand Up @@ -496,5 +500,9 @@ export function extendBaseUrl<Context extends NuxtApp = NuxtApp>(
return baseUrl
}
}
function isI18nRouteDefined(route: Route | RouteLocationNormalized | RouteLocationNormalizedLoaded): boolean {
const i18nLocales = route.matched[0]?.meta.nuxtI18n
return i18nLocales ? Object.keys(i18nLocales).length > 0 : false
}

/* eslint-enable @typescript-eslint/no-explicit-any */

0 comments on commit 182098b

Please sign in to comment.