I am new to Vue.js. I have to show a pop up (seperate ponent) when a user es from a specific path.
I used a show variable which is by default set to true. As user lands on this page, user will see a pop up. But I want to get the path name in my ponent so that I will show the pop up only when a user es from the specific URL.
I used the beforeRouteEnter (to, from, next)
method for getting the previous path. And according to that I am changing the show variable value.
beforeRouteEnter (to, from, next) {
next(vm => {
if (from.path === '/my-specific-path') {
vm.show = true;
}else{
vm.show = false;
});
},
But it is showing my pop up because mounting is done before calling beforeRouteEnter
method.
I am new to Vue.js. I have to show a pop up (seperate ponent) when a user es from a specific path.
I used a show variable which is by default set to true. As user lands on this page, user will see a pop up. But I want to get the path name in my ponent so that I will show the pop up only when a user es from the specific URL.
I used the beforeRouteEnter (to, from, next)
method for getting the previous path. And according to that I am changing the show variable value.
beforeRouteEnter (to, from, next) {
next(vm => {
if (from.path === '/my-specific-path') {
vm.show = true;
}else{
vm.show = false;
});
},
But it is showing my pop up because mounting is done before calling beforeRouteEnter
method.
2 Answers
Reset to default 4beforeRouteEnter (to, from, next) {
next(vm => {
if (from.path === '/my-specific-path') {
vm.show = true;
} else {
vm.show = false;
}
next()
});
},
You are missing the next()
Just fix the brackets
beforeRouteEnter (to, from, next) {
next(vm => {
if (from.path === '/my-specific-path') {
vm.show = true;
}else{
vm.show = false;
} //this bracket missing
});
},