Skip to content

Commit eecada4

Browse files
committed
fix(ui): normalize locale toggle path handling
1 parent db68593 commit eecada4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

frontend/src/components/LocaleToggle.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ export function LocaleToggle() {
88

99
const otherLocale = locale === "ko" ? "en" : "ko";
1010
const toggleLabel = locale === "ko" ? "Switch to English" : "한국어로 전환";
11-
// Replace /{locale}/ prefix in pathname
12-
const newPath = pathname.replace(`/${locale}`, `/${otherLocale}`);
11+
const normalizedPath = pathname.startsWith(`/${locale}`)
12+
? pathname
13+
: `/${locale}${pathname}`;
14+
const safePath = normalizedPath.replace(new RegExp(`^/${locale}(?=/|$)`), `/${otherLocale}`);
15+
16+
// Replace /{locale} prefix in pathname
17+
const newPath = safePath;
1318

1419
return (
1520
<a

0 commit comments

Comments
 (0)