Watch callback not triggered for props of router-view
See original GitHub issueIf a component prop passed through a nested route been changed, watch
callback does not triggered: http://jsfiddle.net/jh9pk6jc/1/
Not sure if it is a vue-router issue
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
vue.js - Watch function is not firing after variable being passed ...
mus as a dependency (similar to computed properties). Whenever route.params.mus changes, the callback will be run again. watch vs watchEffect.
Read more >API Documentation | Vue Router
Component to render a link that triggers a navigation on click. ... Ensures a route is loaded, so it can be passed as...
Read more >Complete Vue Router 4 Guide: Basics, Programmatic Routing ...
We have tried named routes, now let's try named routerViews. RouterView is a built-in component of VueRouter. It has two props: name and...
Read more >API Reference | Vue Router
Allows passing down params as props to the component rendered by router-view . When passed to a multiple views record, it should be...
Read more >Routing in Vue3: Navigating the Options - CODE Magazine
Inside the vue-router package, there's a special component called RouterView . You can simply specify this component where you want it to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh.
I didn’t express myself correctly, but the point is the same:
The
UserHome
components only gets rendered when you visits/user/:id
, not when you visit one of the other routes,user/:id/profile
, for example.As you only have one
<router-link>
that renders theUserHome
component (/user/foo
), the id will not change from the perspective of this component. It will only ever receive the intial valuefoo
of that prop during render. That the id isbar
when you are in another routehas no effect onUserHome
, because the component will not be active in that moment.So: The watch will only be triggered if you switch from one route like
/user/foo
to the same route with a different id, e.g./user/bar
- not a different route, e.g./user/bar/profile
To demonstrate this, I have added a second route that will render
UserHome
as well,/user/bar
, here:http://jsfiddle.net/Linusborg/jh9pk6jc/3/
If you switch between the first two links, you will see the watch being triggered in the console.
And again: If it should trigger immediatly, use the
immediate
optionThe functionality also works across different routes:
http://jsfiddle.net/Linusborg/jh9pk6jc/5/
as long as it renderes the same component - that was your problem, not routes / route-params.