vue路由 Maximum call stack size exceeded
生活随笔
收集整理的這篇文章主要介紹了
vue路由 Maximum call stack size exceeded
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.問題:在Vue項目開發(fā)中遇到根據(jù)登錄來判斷頁面跳轉(zhuǎn)時遇到死循環(huán)的問題。
2.錯誤代碼如下:
const router = new VueRouter({mode: 'history',base: process.env.BASE_URL,routes }) const token = store.getters.getToken router.beforeEach((to, from, next) => {if (!token) {next({ name: 'error' })}// 有權(quán)限next() }) export default router3.解決辦法如下
router.beforeEach((to, from, next) => {const excludePath = ['error']if (!token && excludePath.indexOf(to.name) === -1) {next({ name: 'error' })}// 有權(quán)限next() })總結(jié):在使用路由守衛(wèi)時,需有相應(yīng)的結(jié)束條件,否則會一直循環(huán)下去。
總結(jié)
以上是生活随笔為你收集整理的vue路由 Maximum call stack size exceeded的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转载】VC项目配置基础
- 下一篇: vue日历插件vue-calendar