diff --git a/packages/website/src/components/LocaleRedirector.astro b/packages/website/src/components/LocaleRedirector.astro index d66b93723..b234ba4f3 100644 --- a/packages/website/src/components/LocaleRedirector.astro +++ b/packages/website/src/components/LocaleRedirector.astro @@ -7,18 +7,18 @@ window.location.pathname.startsWith(`/${locale}`) ); const bestLocale = getBestLocale(); - const currentPathLocale = locales.supported.find(({ locale }) => + const currentPath = locales.supported.find(({ locale }) => window.location.pathname.startsWith(`/${locale}`) ); if ( !isAPI && // not an api, duh! localStorage.getItem("preferred-locale") !== null && // no preference, so probably google's crawler - bestLocale !== currentPathLocale // we need to redirect + bestLocale !== currentPath?.locale // we need to redirect ) { window.location.pathname = isI18nPath ? window.location.pathname.replace( - `/${currentPathLocale}`, + `/${currentPath?.locale}`, bestLocale === undefined ? "" : `/${bestLocale}` ) : `/${bestLocale}${window.location.pathname}`;