NavigationDuplicated //vue-router路由连续跳转两次报错

控制台报错NavigationDuplicated
原因:vue-router升级3.1.0版本之后,引入promise的语法,出现的问题
解决方案:

1.为每一个增加回调函数,vue-router的开发者给出了解决方法
2.将vue-router版本降低到3.1.0版本以下
3.重写原型上的push/replace方法

 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)
 }
 ```
posted @ 2022-02-23 10:30  w1ndz  阅读(267)  评论(0)    收藏  举报