【问题标题】:RangeError: Maximum call stack size exceeded Vue routerRangeError:超出了最大调用堆栈大小 Vue 路由器
【发布时间】:2021-05-25 13:35:45
【问题描述】:

我想用vue js写一个登录来做这个,我先写了这个

我收到此错误(范围错误:超出最大调用堆栈大小)

【问题讨论】:

    标签: vue.js vuejs2 vue-router


    【解决方案1】:

    我认为你的beforeEach 也为login 运行,因此它进入了一个无限循环,一遍又一遍地重定向到/login

    尝试再添加一个条件,如下所示:-

    router.beforeEach((to, from, next) => {
      let isAuthenticate = false;
    
      if(localStorage.getItem('user')) {
        isAuthenticate = true;
      } 
      if(isAuthenticate && to.name !== 'login') {
        next();
      } else if(isAuthenticate) {
        next('/Dashboard/home')
      } else if(to.name === 'login') {
        next();
      } else {
        next('login')
      }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-11
      • 2017-05-23
      • 2020-11-19
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      相关资源
      最近更新 更多