vueRouter:Avoided redundant navigation to current location

1、問題描述:

最近使用ElementUI的NavMenu 導航菜單組件的時候,發現一個導航被重複點擊的時候,

element-ui.common.js?b705:3354 Error: Avoided redundant navigation to current location: "/management/arrange".
    at createRouterError (vue-router.esm.js?fe79:2060)
    at createNavigationDuplicatedError (vue-router.esm.js?fe79:2033)
    at HTML5History.confirmTransition (vue-router.esm.js?fe79:2182)
    at HTML5History.transitionTo (vue-router.esm.js?fe79:2123)
    at HTML5History.push (vue-router.esm.js?fe79:2479)
    at VueRouter.push (vue-router.esm.js?fe79:2903)
    at VueComponent.routeToItem (element-ui.common.js?b705:3381)
    at VueComponent.handleItemClick (element-ui.common.js?b705:3348)
    at invokeWithErrorHandling (vue.runtime.esm.js?0261:1854)
    at VueComponent.Vue.$emit (vue.runtime.esm.js?0261:3888)

2、解決方案,在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)
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章