Reputation: 2370
Reproduction link https://codesandbox.io/s/vue-template-c2gtb
Steps to reproduce
Open https://codesandbox.io/s/vue-template-c2gtb
Click on 'Go to Page with nested router' link
Click on 'commit event', it will show an alert box
Now change the nested route by clicking 'change nested route to reporting'
What is expected? Route changed to reporting without showing the 'hello' alert box.
What is actually happening? Its showing the 'hello' alert box again.
Upvotes: 0
Views: 28
Reputation: 14269
You should change your watcher to ignore cases when old value is the same as new value:
watch: {
event: {
handler(newVal,oldVal) {
if(oldVal === newVal) return; // <--- the important part
switch (this.event.id) {
case 'new_requirement': {
alert('hello');
break;
}
default:
}
},
},
},
Upvotes: 1