From 411806d5ce5f8bbe1dd290834bdcc486d7fe9857 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 14 Jan 2026 16:27:20 +0000 Subject: [PATCH] fix(i18n): use hard navigation for language switch Switch locales via window.location.assign to guarantee the URL and messages update even if client-side router navigation is blocked. Co-authored-by: dennis --- app/components/Header.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/components/Header.tsx b/app/components/Header.tsx index 95ac994..441230f 100644 --- a/app/components/Header.tsx +++ b/app/components/Header.tsx @@ -49,10 +49,14 @@ const Header = () => { 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}`); - router.refresh(); + // Use a hard navigation for maximum reliability (also fixes cases where + // client-side router navigation can be prevented by runtime errors). + const target = `/${nextLocale}${pathWithoutLocale}${hash}`; + if (typeof window !== "undefined") { + window.location.assign(target); + return; + } + router.push(target); } catch { // ignore }