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) => {
// to 將要訪問的路徑
// from 代表從哪個路徑跳轉而來
// next 表示函式 表示放行
// next() 放行 next('/login') 強制跳轉
console.log(to.path);
if (to.path === './login') return next() //登入頁放行
// 獲取token const tokenStr = window.sessionStorage.getItem('token') if (!tokenStr) return next('/login') // 41 行 next()
})
發現to.path 的值其實等於'/login' 所以一直無限迴圈比較
(PS:為什麼昨天能執行,我人都傻了)