Getting previous route info before rendering in vue js?
beforeRouteEnter (to, from, next) {
next(vm => {
if (from.path === '/my-specific-path') {
vm.show = true;
} else {
vm.show = false;
}
next()
});
},
You are missing the next()
Pulkit Aggarwal
I am simple hearted guy and always ready to help needy one. I am an optimistic person and loves to fight with various challenges of life. I am an technogeek who always looks for the new ideas and innovations. I believe in knowledge sharing. Currently, I am working as Software Engineer at kelltontech Solutions Ltd.
Updated on June 14, 2022Comments
-
Pulkit Aggarwal almost 2 years
I am new to Vue.js. I have to show a pop up (seperate component) when a user comes 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 component so that I will show the pop up only when a user comes from the specific URL.
I used thebeforeRouteEnter (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. -
Pulkit Aggarwal about 6 yearsI am updating the
show varibale
in next function. -
Ru Chern Chong about 6 yearsYou have to proceed after you finished modifying the
show
variable. -
Pulkit Aggarwal about 6 yearsI don't know why my code is now running wihout adding next()
-
Ru Chern Chong about 6 yearsOh okay. That’s interesting