问题描述:
使用vue-router设置二级跳转时出现这样的错误:
原因分析:
NavigationDuplicated错误就是重复跳转同一个导航,如果每次点击的是不同的路径就不会报错,如果你已经在本页面了,还点击本页面的导航,就会出现这个错误。
解决方法:
在路由设置页面(我是在src下router文件夹里的index.js设置的)添加如下代码:
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 新增以下代码,解决NavigationDuplicated问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
};
这样就不会报错了。