Reputation: 4782
I've the following use-case:
/parent
page and Parent component is rendered/parent/john
and the Child component is rendered/parent
the child component is destroyedAt this point I need to update the Parent component. I've the following routes.js:
{
path: '/parent',
name: 'parent',
component: Parent,
beforeEnter: (to, from, next) => {
console.log(to, from);
next();
},
children: [
{
path: ':child',
component: Child
},
]
},
Since beforeEnter
the first time the component is rendered is there any other way to know that the route was updated and trigger a method on the Parent component?
Upvotes: 1
Views: 2134
Reputation: 1471
I think reacting-to-params-changes may be helpful.
Basically, after registering vue-router all components will have the '$router' and '$route' attributes.
component.$router can be used to bind listeners and change the current route programatically.
component.$route holds the information about the current route.
So, one alternative is watch the '$route' attribute.
const User = {
template: '...',
watch: {
'$route' (to, from) {
// react to route changes...
}
}
}
Upvotes: 2