https://codesandbox.io/s/yq22jokp0v
/foo/1
Bar 2
link (The link only changes the bar param -> see URL)Reproduction repo: https://github.com/christopheschwyzer/nuxt-dynamic-routes-bug
Deployed also here: https://condescending-bhabha-c04b2c.netlify.com/foo/1
I understand from the vue-router documentation that the component shouldn't be recreated in such case?
Note: If the destination is the same as the current route and only params are changing (e.g. going from one profile to another /users/1 -> /users/2), you will have to use beforeRouteUpdate to react to changes (e.g. fetching the user information).
Page is recreated.
Hi @christopheschwyzer , the issue is because the key
of RouterView
is different between /foo/1
and /foo/2
, for now you can specify key
to ensure view is same one:
<script>
export default {
key: '_bar',
created() {
console.log("created");
}
};
</script>
@clarkdo Thank you, works great!
As I'm not sure what the (default) behavior should be I'll keep the issue open - but feel free to close it.
Well, either it has to be well documented or changed 鈽猴笍
I think such behavior is needed for transitions but I could be wrong.
cc @pi0 (is that behavior intended or even required?)
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as 馃晲Pending
will not be automatically marked as stale.
Hey there 馃憢
Indeed, the key
is made for the transitions to work seamlessly by default. This behaviour will be better documented in the future, thank you for reporting it @christopheschwyzer
@clarkdo's comment should solve your issue if you don't want any re-creation of the view :)
Most helpful comment
Hi @christopheschwyzer , the issue is because the
key
ofRouterView
is different between/foo/1
and/foo/2
, for now you can specifykey
to ensure view is same one: