New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear way to re-use the component of the matched page when language switching causes a navigation to a different locale prefix #2853
Comments
I tried to double-check the documentation for any snippets or info I might've missed on this, but at the time of writing the documentation is broken. |
Sorry about that, the documentation was broken yesterday but it should be working again!
This is intended behaviour, when switching between languages you're essentially navigating to a different page with the same behaviour as you normally would experience. I think using a Could you create a reproduction to show an example of page state that is lost/re-rendered? |
Minimal example: After clone, Should see 3 things:
Without the workaround:
To enable the workaround, uncomment With the workaround enabled:
This behavior is what I would prefer in most cases, because
I do like the granularity of specifying on which pages I want to have either behavior, via the I'd love an importable utility like |
@danwithabox |
Indeed, I knew I forgot something! Should be good now, cheers 🫠 |
Closing due to inactivity. Thanks! |
I will risk it and ping @BobbieGoede, I don't think this issue should be closed before input from you, maybe I should've pinged when I made my repo public 🤷♂️ I don't think opening a new issue just to bump this would be appreciated. And I can't really "follow up with more information" until some reaction to my repro / example 😅 |
Ah I did somehow forget to check this out again, the ping was necessary 😅.. I still have to give it a thorough look, I understand the benefits of not mounting the page again but we should consider what could be possible drawbacks as well. There's been a few PRs with feature proposals that also touch on some core features that could have some overlap with each other including this, I'll reopen this and assign myself so we can keep the discussion open and I will look into it when I have more time 😥. |
Describe the feature
I wish to keep page state when a language switcher causes the URL to change.
Currently, out-of-the-box, the URL change causes a component re-render.
I would have guessed Vue router's goal of re-using and updating components when possible would apply, since the pages are the same, only the locale have changed.
Instead, a console log on
onMounted
shows that a fresh component is mounted.Is this intended behaviour?
It seems counter-intuitive to me, but I have not found documentation nor issues about.
I tried a quick workaround (in
pages/index.ts
):This works, since the postfixed pathnames seem to use a
___
separator, e.g.:With some more digging around, I changed the code to make it less hacky by avoiding the magic string
___
:I am definitely not sure that this is the best way to achieve what I want.
Could we have a dedicated option for this, or at least an official snippet in the documentation?
Additional information
Final checks
The text was updated successfully, but these errors were encountered: