Vue的路由守卫
2023-11-16 本文已影响0人
Frank_Fang
增加了路由守卫后,会报错
// 路由守卫
router.beforeEach((to, from, next) => {
const isLogin = this.$Utils.getToken()
if (isLogin) {
next()
} else {
if (to.path === '/login') {
console.log(to)
next()
} else {
next({
path: '/login'
})
}
}
})
加上下面这段代码就行了
// fix Redirected when going from "/xxx" to "/yyy" via a navigation guard
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}