fix: sync language prefixes

This commit is contained in:
TerryM
2026-06-01 16:36:55 +08:00
parent da4c13f304
commit 56d6bd033d
2 changed files with 23 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ import {
homePathForLang,
isHomePathname,
languageFromPathname,
localizePath,
stripLangPrefix,
} from "../languageRoutes";
import { useLocalizedPath } from "../useLocalizedPath";
@@ -318,7 +319,15 @@ export function PublicLayout() {
const homePath = homePathForLang(lang);
const changeLang = (nextLang: Lang) => {
setLang(nextLang);
if (isHome) nav(homePathForLang(nextLang), { replace: true });
if (isHome) {
nav(homePathForLang(nextLang), { replace: true });
} else {
// Preserve sub-path and query/hash; only swap the language prefix.
const canonical = stripLangPrefix(pathname);
nav(localizePath(canonical, nextLang) + search + hash, {
replace: true,
});
}
};
const footerInContentFlow = stripLangPrefix(pathname) === "/browse";
// Current page name shown in the header brand slot (falls back to the brand).