FarazShuja
FarazShuja

Reputation: 2370

Switching to a nested route is automatically running the last commit event from parent's store

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

Answers (1)

IVO GELOV
IVO GELOV

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

Related Questions