vue中router路由重复跳转Avoided redundant navigation to current location Redirected when going from...

在使用ElementUI或vue组件中的导航时,默认情况下如果重复点击某选项,会报错。

element-ui.common.js?b705:3354 Error: Avoided redundant navigation to current location: “/home/home1”.

问题原因一样 重复访问同一个路由地址 

可以在router的配置文件中(router -> index.js)加上下面这句话,注意位置:

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

......

 

posted @ 2023-06-22 20:39  JackieDYH  阅读(163)  评论(0编辑  收藏  举报  来源