Vue - 项目中报错Error: Avoided redundant navigation to current location: “/xxx“.的解决方案
在一个vue项目中重复跳转到同一个路由地址时报错!
报错显示路由重复,对功能没有影响。
解决方法
在入口文件下添加代码:
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
// 重写了原型上的push方法,统一的处理了错误信息
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}