Whole page gets re-mounted after a locale change? #723
Unanswered
nikola1970
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Next.js remounting the page on locale change is expected since this is essentially a navigation to another page (see e.g. vercel/next.js#44793). If you want to persist some state between navigation, you need to move it out of the local state of a component that gets remounted (e.g. to a context value that is rendered from the root layout). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, so everything looks to work fine besides that whenever I switch locale whole page gets re-mounted (very short blank flash) for some reason.
I am consuming all my translations
client side
.App structure is like this:
app/[locale]/layout.tsx
etc, so all pages are nested inside locale folder.My
[locale]/layout.tsx
looks like this:My navigation utils file is this:
And middleware is like this:
When using the link provided by
createSharedPathnamesNavigation
, it triggers a full-page reload. Because of this, I utilize the next/navigation link with appropriate linking to switch the language, and that works fine without hard-refreshing the page.The only issue I encounter is that the page gets re-mounted upon any locale switch. For instance, if I have a form with input fields, and some of them are filled, switching the locale causes everything to be lost because the entire page is being remounted.
Any ideas? :) Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions