From 9563ad598764492d0d7b1a45c06f814e11ed7d33 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Tue, 22 Jul 2025 14:11:38 +0700 Subject: [PATCH] fix:content filter query --- .../partials/header/locale-switcher.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/components/partials/header/locale-switcher.tsx b/components/partials/header/locale-switcher.tsx index 31fddafd..b0b359a4 100644 --- a/components/partials/header/locale-switcher.tsx +++ b/components/partials/header/locale-switcher.tsx @@ -1,7 +1,7 @@ "use client"; import { useLocale } from "next-intl"; -import { useParams } from "next/navigation"; +import { useParams, useSearchParams } from "next/navigation"; import { locales } from "@/config"; import { usePathname, useRouter } from "@/i18n/routing"; @@ -33,13 +33,22 @@ export default function LocalSwitcher() { const params = useParams(); const localActive = useLocale() || "in"; const [selectedLang, setSelectedLang] = useState(""); + const searchParams = useSearchParams(); useEffect(() => { const storedLang = getLanguage(); + let joinParam = ""; + if (searchParams) { + joinParam = Array.from(searchParams.entries()) + .map(([key, value]) => `${key}=${value}`) + .join("&"); + } - if (pathname.includes("polda")){ + if (pathname.includes("polda")) { startTransition(() => { - router.replace(pathname, { locale: "in" }); + router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, { + locale: "in", + }); }); } else { if (!storedLang) { @@ -47,16 +56,20 @@ export default function LocalSwitcher() { setSelectedLang("in"); startTransition(() => { - router.replace(pathname, { locale: "in" }); + router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, { + locale: "in", + }); }); } else { setSelectedLang(storedLang); startTransition(() => { - router.replace(pathname, { locale: storedLang }); + router.replace(pathname + joinParam === "" ? "" : `?${joinParam}`, { + locale: storedLang, + }); }); } } - }, []); + }, [searchParams]); const onSelectChange = (nextLocale: string) => { setLanguage(nextLocale);