From my main vue instance I am trying to detect when a route is changed. So far what i have learned that i need to deep watch an object to detect property changes. But my approach is not working. What am i doing wrong:
const app1 = new Vue({
el: '#app1',
router,
data: {
activeRoute: router.currentRoute
},
methods: {
printclass: function() {
console.log(router.currentRoute.path);
}
},
computed: {
},
watch: {
'router.currentRoute': {
handler(newVal) {
console.log('changed');
}, deep: true
}
},
created: function() {
console.log(router.currentRoute);
}
});
I know that the currentRoute object's path property changes when the route changes(i.e; a different component is rendered).