解决 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)
}

浙公网安备 33010602011771号