Skip to content

Commit 5298969

Browse files
committed
switch locale as recommended
1 parent 1e40746 commit 5298969

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/LanguagePicker/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useParams } from "next/navigation"
2+
13
import { BaseLink } from "@/components/Link"
24

35
import { cn } from "@/lib/utils/cn"
@@ -36,6 +38,7 @@ const LanguagePicker = ({
3638
}: LanguagePickerProps) => {
3739
const pathname = usePathname()
3840
const { push } = useRouter()
41+
const params = useParams()
3942
const { disclosure, languages } = useLanguagePicker(handleClose)
4043
const { isOpen, setValue, onClose, onOpen } = disclosure
4144

@@ -52,9 +55,15 @@ const LanguagePicker = ({
5255
// onClick handlers
5356
const handleMobileCloseBarClick = () => onClose()
5457
const handleMenuItemSelect = (currentValue: string) => {
55-
push(pathname, {
56-
locale: currentValue,
57-
})
58+
push(
59+
// @ts-expect-error -- TypeScript will validate that only known `params`
60+
// are used in combination with a given `pathname`. Since the two will
61+
// always match for the current route, we can skip runtime checks.
62+
{ pathname, params },
63+
{
64+
locale: currentValue,
65+
}
66+
)
5867
onClose({
5968
eventAction: "Locale chosen",
6069
eventName: currentValue,

0 commit comments

Comments
 (0)