fix: ensure navLinks use correct locale from prop
The navLinks were using localePath which was derived from locale but the switchLocale was using pathname directly. This caused mismatch when switching languages.
This commit is contained in:
@@ -48,12 +48,9 @@ export default function Header({ locale = "sr" }: HeaderProps) {
|
||||
setLangDropdownOpen(false);
|
||||
return;
|
||||
}
|
||||
console.log("Switching from", locale, "to", newLocale);
|
||||
console.log("Current pathname:", pathname);
|
||||
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
|
||||
const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/";
|
||||
const newPath = `/${newLocale}${pathWithoutLocale}`;
|
||||
console.log("Navigating to:", newPath);
|
||||
window.location.replace(newPath);
|
||||
setLangDropdownOpen(false);
|
||||
};
|
||||
@@ -82,9 +79,9 @@ export default function Header({ locale = "sr" }: HeaderProps) {
|
||||
}, [mobileMenuOpen]);
|
||||
|
||||
const navLinks = [
|
||||
{ href: `${localePath}/products`, label: t("products") },
|
||||
{ href: `${localePath}/about`, label: t("about") },
|
||||
{ href: `${localePath}/contact`, label: t("contact") },
|
||||
{ href: `/${locale}/products`, label: t("products") },
|
||||
{ href: `/${locale}/about`, label: t("about") },
|
||||
{ href: `/${locale}/contact`, label: t("contact") },
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user