vue-router Uncaught (in promise) NavigationDuplicated 错误

使用 vue-router 编程式实现页面跳转

this.$router.replace({ path: '/pub' });

出现错误如下图

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

 解决办法:

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

npm i vue-router@3.0.7 -S

2、给 this.$router.replace() 方法添加回调

this.$router.replace({ path: '/pub' }).catch(() => { });

注:this.$router.push() 方法也存在同样问题,可以同样处理

原文地址:https://www.cnblogs.com/laoq112/p/11946832.html