在VUE中路由遇到Error: Avoided redundant navigation to current location:报错显示是路由重复

  1. 首先打开我们的路由配置文件,router文件夹下的index.js。
  2. 在index.js添加如下代码
import Vue from 'vue';

import VueRouter from 'vue-router';

Vue.use(VueRouter);

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

  1. 如果修改了还是没有生效,那么可以尝试replace方法,例如:
const originalReplace = VueRouter.prototype.replace;
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

Logo

前往低代码交流专区

更多推荐