Skip to content

Commit 80f2333

Browse files
committed
fix(i18n): preserve locale toggle query state
1 parent fd81086 commit 80f2333

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

frontend/src/components/LocaleToggle.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
"use client";
22

3-
import { useParams, usePathname } from "next/navigation";
3+
import { useMemo } from "react";
4+
import { useParams, usePathname, useSearchParams } from "next/navigation";
45

56
export function LocaleToggle() {
67
const { locale } = useParams<{ locale: string }>();
78
const pathname = usePathname();
9+
const searchParams = useSearchParams();
810

911
const otherLocale = locale === "ko" ? "en" : "ko";
1012
const toggleLabel = locale === "ko" ? "Switch to English" : "한국어로 전환";
1113
const normalizedPath = pathname.startsWith(`/${locale}`)
1214
? pathname
1315
: `/${locale}${pathname}`;
1416
const safePath = normalizedPath.replace(new RegExp(`^/${locale}(?=/|$)`), `/${otherLocale}`);
15-
16-
// Replace /{locale} prefix in pathname
17-
const newPath = safePath;
17+
const queryString = useMemo(() => searchParams.toString(), [searchParams]);
18+
const newPath = queryString ? `${safePath}?${queryString}` : safePath;
1819

1920
return (
2021
<a
2122
href={newPath}
2223
className="flex items-center gap-1.5 px-3 py-1.5 border border-hud-border hover:border-accent bg-void-light/80 rounded font-mono text-sm text-hud-muted hover:text-accent transition-colors"
2324
title={toggleLabel}
24-
aria-label={toggleLabel}
25+
aria-label={`${toggleLabel}. Keep current filters and view state.`}
2526
>
2627
<span className={locale === "ko" ? "text-hud-muted" : "text-accent font-semibold"}>EN</span>
2728
<span className="text-hud-label">/</span>

0 commit comments

Comments
 (0)