2021-06-13

标题 veu路由版本问题vue-router.esm.js?fe87:2062 Uncaught (in promise) Error: Avoided redundant navigation to current loc

vue报错
vue-router.esm.js?fe87:2062 Uncaught (in promise) Error: Avoided redundant navigation to current location: “/userPage”.
at createRouterError (vue-router.esm.js?fe87:2062)
at createNavigationDuplicatedError (vue-router.esm.js?fe87:2035)
at HashHistory.confirmTransition (vue-router.esm.js?fe87:2195)
at HashHistory.transitionTo (vue-router.esm.js?fe87:2125)
at HashHistory.push (vue-router.esm.js?fe87:2595)
at eval (vue-router.esm.js?fe87:2913)
at new Promise ()
at VueRouter.push (vue-router.esm.js?fe87:2912)
at VueComponent.created (indexPage.vue?8cc2:96)
at invokeWithErrorHandling (vue.esm.js?efeb:1863)

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

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

import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../components/login/login.vue'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
 return originalPush.call(this, location).catch(err => err)
}


版权声明:本文为weixin_46548946原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。