Uncaught (in promise)NavigationDuplicated{_name:“NavigationDuplicated”}
最近在vue项目中遇到个问题——点击侧边栏路由跳转时在控制台报错,如下图所示:
vue-router 3
以上版本回调形式改成promise api
的形式了,返回的是一个promise
,3.0以下
版本则不会出现上面的警告⚠️。
解决方案如下:
-
方案1
在main.js中加入如下代码:
import Router from 'vue-router' const routerPush = Router.prototype.push Router.prototype.push = function push(location) { return routerPush.call(this, location).catch(error=> error) }
-
方案2
安装vue-router版本
npm i vue-router@3.0 -S