Getting previous route info before rendering in vue js?

11,083
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()

Share:
11,083
Pulkit Aggarwal
Author by

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, 2022

Comments

  • Pulkit Aggarwal
    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 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.

  • Pulkit Aggarwal
    Pulkit Aggarwal about 6 years
    I am updating the show varibale in next function.
  • Ru Chern Chong
    Ru Chern Chong about 6 years
    You have to proceed after you finished modifying the show variable.
  • Pulkit Aggarwal
    Pulkit Aggarwal about 6 years
    I don't know why my code is now running wihout adding next()
  • Ru Chern Chong
    Ru Chern Chong about 6 years
    Oh okay. That’s interesting