解决 Uncaught (in promise) NavigationDuplicated 报错问题

 原因是:vue-router 在 3.1 版本之后把 this.$router.replace() 方法改为了 Promise,没有回调函数时错误信息就会由全局显示

 

 解决办法:

1、降低 vue-router 版本到 3.0.7 以下

npm install vue-router@3.0.7 -s

2、给 this.$router.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 @ 2021-12-10 21:12  kai·james  阅读(379)  评论(0)    收藏  举报