From f95585af5834b84a1bddbb0cec1bb551dc80b595 Mon Sep 17 00:00:00 2001 From: Unchained Date: Tue, 24 Mar 2026 08:12:11 +0200 Subject: [PATCH] fix: language switcher path bug causing /en/en/checkout --- src/components/layout/Header.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); };