File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
56export 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 >
You can’t perform that action at this time.
0 commit comments