's'
This commit is contained in:
@@ -85,15 +85,18 @@ export function useTranslation(namespace?: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function navigate(pathname: string, locale: Locale, opts?: { locale?: Locale }) {
|
||||
const newLocale = opts?.locale ?? locale;
|
||||
const cleanPath = pathname.replace(/^\/(zh|en)/, "") || "/";
|
||||
const newPath = `/${newLocale}${cleanPath === "/" ? "" : cleanPath}`;
|
||||
window.location.href = newPath;
|
||||
}
|
||||
|
||||
export function useLocaleRouter() {
|
||||
const locale = useLocale();
|
||||
return {
|
||||
replace: (pathname: string, opts?: { locale?: Locale }) => {
|
||||
const newLocale = opts?.locale ?? locale;
|
||||
const cleanPath = pathname.replace(/^\/(zh|en)/, "") || "/";
|
||||
const newPath = `/${newLocale}${cleanPath === "/" ? "" : cleanPath}`;
|
||||
window.location.href = newPath;
|
||||
},
|
||||
push: (pathname: string, opts?: { locale?: Locale }) => navigate(pathname, locale, opts),
|
||||
replace: (pathname: string, opts?: { locale?: Locale }) => navigate(pathname, locale, opts),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user