fix: redirect

This commit is contained in:
TrèsAbhi committed 2025-09-29 13:35:47 -05:00
1 parent a359897a2a
commit 61d1ebbad6
1 file changed
+3 -3
@@ -7,18 +7,18 @@
window.location.pathname.startsWith(`/${locale}`) window.location.pathname.startsWith(`/${locale}`)
); );
const bestLocale = getBestLocale(); const bestLocale = getBestLocale();
const currentPathLocale = locales.supported.find(({ locale }) => const currentPath = locales.supported.find(({ locale }) =>
window.location.pathname.startsWith(`/${locale}`) window.location.pathname.startsWith(`/${locale}`)
); );
if ( if (
!isAPI && // not an api, duh! !isAPI && // not an api, duh!
localStorage.getItem("preferred-locale") !== null && // no preference, so probably google's crawler 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 = isI18nPath
? window.location.pathname.replace( ? window.location.pathname.replace(
`/${currentPathLocale}`, `/${currentPath?.locale}`,
bestLocale === undefined ? "" : `/${bestLocale}` bestLocale === undefined ? "" : `/${bestLocale}`
) )
: `/${bestLocale}${window.location.pathname}`; : `/${bestLocale}${window.location.pathname}`;