Maximum call stack size exceeded 报错
重启路由之后遇到报错
Maximum call stack size exceeded 字面意思是栈溢出
RangeError: Maximum call stack size exceeded
at abort (vue-router.esm.js?8c4f:2180)
at iterator (vue-router.esm.js?8c4f:2251)
at step (vue-router.esm.js?8c4f:1896)
at runQueue (vue-router.esm.js?8c4f:1904
at HashHistory.confirmTransition (vue-router.esm.js?8c4f:2255)
at HashHistory.transitionTo (vue-router.esm.js?8c4f:2125)
at HashHistory.push (vue-router.esm.js?8c4f:2595)
at eval (vue-router.esm.js?8c4f:2243
at eval (index.js?a18c:41)
at iterator (vue-router.esm.js?8c4f:2225)
于是我去index.js 41行看了一下
router.beforeEach((to, from, next) => {
console.log(to.path);
if (to.path === '/login') return next() //登录页放行
// 获取token
const tokenStr = window.sessionStorage.getItem('token')
if (!tokenStr) return next('/login')
next()
})
发现to.path 的值其实等于'/login' 所以一直无限循环比较
(PS:为什么昨天能运行,我人都傻了)