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:
Cursor Agent
2026-01-14 16:21:18 +00:00
parent 355c9a13fa
commit c150cd82d9

View File

@@ -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
}