fix: language switcher path bug causing /en/en/checkout

This commit is contained in:
Unchained
2026-03-24 08:12:11 +02:00
parent a84647db6c
commit f95585af58

View File

@@ -45,9 +45,13 @@ export default function Header({ locale = "sr" }: HeaderProps) {
}, []);
const switchLocale = (newLocale: string) => {
if (newLocale === locale) {
setLangDropdownOpen(false);
return;
}
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
const currentPath = pathname.replace(`/${locale}`, "") || "/";
const newPath = newLocale === "sr" ? currentPath : `/${newLocale}${currentPath}`;
const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/";
const newPath = newLocale === "sr" ? pathWithoutLocale : `/${newLocale}${pathWithoutLocale}`;
router.push(newPath);
setLangDropdownOpen(false);
};