fix(i18n): make locale switch always navigate
Stop setting NEXT_LOCALE cookie client-side and refresh after navigation, avoiding swallowed cookie errors that can prevent router.push from switching languages. Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
@@ -48,8 +48,11 @@ const Header = () => {
|
||||
try {
|
||||
const pathWithoutLocale = pathname.replace(new RegExp(`^/${locale}`), "") || "";
|
||||
const hash = typeof window !== "undefined" ? window.location.hash : "";
|
||||
// Rely on middleware to persist NEXT_LOCALE cookie.
|
||||
// Avoid setting cookies from the client here; in some environments this can throw
|
||||
// and prevent navigation.
|
||||
router.push(`/${nextLocale}${pathWithoutLocale}${hash}`);
|
||||
document.cookie = `NEXT_LOCALE=${nextLocale}; path=/`;
|
||||
router.refresh();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user