问题
vue系统按权限设置动态路由,切换路由时触发该错误
解决方案
1. 切换路由前设置好token
2. 降低 vue-router 版本
3. 优化 VueRouter.prototype.push
- 在
router/index.js
文件中设置VueRouter
原型上的push
方法
// 解决触发导航守卫问题
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)
}