diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx index c99f842..077fc2c 100644 --- a/src/components/layout/Header.tsx +++ b/src/components/layout/Header.tsx @@ -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); };