fix: language switcher path bug causing /en/en/checkout
This commit is contained in:
@@ -45,9 +45,13 @@ export default function Header({ locale = "sr" }: HeaderProps) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const switchLocale = (newLocale: string) => {
|
const switchLocale = (newLocale: string) => {
|
||||||
|
if (newLocale === locale) {
|
||||||
|
setLangDropdownOpen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
|
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
|
||||||
const currentPath = pathname.replace(`/${locale}`, "") || "/";
|
const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/";
|
||||||
const newPath = newLocale === "sr" ? currentPath : `/${newLocale}${currentPath}`;
|
const newPath = newLocale === "sr" ? pathWithoutLocale : `/${newLocale}${pathWithoutLocale}`;
|
||||||
router.push(newPath);
|
router.push(newPath);
|
||||||
setLangDropdownOpen(false);
|
setLangDropdownOpen(false);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user