最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting previous route info before rendering in vue js? - Stack Overflow

programmeradmin0浏览0评论

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.

Share Improve this question edited Feb 26, 2018 at 9:37 Pulkit Aggarwal asked Feb 26, 2018 at 8:27 Pulkit AggarwalPulkit Aggarwal 1371 gold badge3 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4
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()

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
  });
},
发布评论

评论列表(0)

  1. 暂无评论