question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watch callback not triggered for props of router-view

See original GitHub issue

If 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:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LinusBorgcommented, Oct 13, 2016

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 the UserHome component (/user/foo), the id will not change from the perspective of this component. It will only ever receive the intial value foo of that prop during render. That the id is bar when you are in another routehas no effect on UserHome, 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 option

0reactions
LinusBorgcommented, Oct 13, 2016

The 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found