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:
Unchained
2026-03-24 11:11:15 +02:00
parent bd95705d72
commit 52b2eac5b5

View File

@@ -48,12 +48,9 @@ export default function Header({ locale = "sr" }: HeaderProps) {
setLangDropdownOpen(false); setLangDropdownOpen(false);
return; return;
} }
console.log("Switching from", locale, "to", newLocale);
console.log("Current pathname:", pathname);
document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`; document.cookie = `NEXT_LOCALE=${newLocale}; path=/; max-age=31536000`;
const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/"; const pathWithoutLocale = pathname.replace(/^\/(sr|en|de|fr)/, "") || "/";
const newPath = `/${newLocale}${pathWithoutLocale}`; const newPath = `/${newLocale}${pathWithoutLocale}`;
console.log("Navigating to:", newPath);
window.location.replace(newPath); window.location.replace(newPath);
setLangDropdownOpen(false); setLangDropdownOpen(false);
}; };
@@ -82,9 +79,9 @@ export default function Header({ locale = "sr" }: HeaderProps) {
}, [mobileMenuOpen]); }, [mobileMenuOpen]);
const navLinks = [ const navLinks = [
{ href: `${localePath}/products`, label: t("products") }, { href: `/${locale}/products`, label: t("products") },
{ href: `${localePath}/about`, label: t("about") }, { href: `/${locale}/about`, label: t("about") },
{ href: `${localePath}/contact`, label: t("contact") }, { href: `/${locale}/contact`, label: t("contact") },
]; ];
return ( return (