Skip to content

Commit cd610d0

Browse files
Merge pull request #223 from mercurjs/fix/mm2-1571/404-redirect-link-not-working
MM2-1571 Fix: remove undefined locale when navigating from 404 page
2 parents 913eb84 + 8ea32ab commit cd610d0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/molecules/LocalizedLink/LocalizedLink.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import Link from "next/link"
4-
import { useParams } from "next/navigation"
4+
import { useParams, usePathname } from "next/navigation"
55
import React, { MouseEventHandler } from "react"
66

77
/**
@@ -20,7 +20,10 @@ const LocalizedClientLink = ({
2020
passHref?: true
2121
[x: string]: any
2222
}) => {
23-
const { locale } = useParams()
23+
const params = useParams()
24+
const pathname = usePathname()
25+
26+
const locale = params?.locale || pathname?.split('/')[1] || 'en'
2427

2528
return (
2629
<Link href={`/${locale}${href}`} {...props}>

0 commit comments

Comments
 (0)