重复点击菜单报错误代码如下:
Error: Avoided redundant navigation to current location: “/users”.
at createRouterError (vue-router.esm.js?8c4f:2062)
at createNavigationDuplicatedError (vue-router.esm.js?8c4f:2035)
at HashHistory.confirmTransition (vue-router.esm.js?8c4f:2195)
at HashHistory.transitionTo (vue-router.esm.js?8c4f:2125)
at HashHistory.push (vue-router.esm.js?8c4f:2595)
at VueRouter.push (vue-router.esm.js?8c4f:2916)
at VueComponent.routeToItem (menu.js?443e:796)
at VueComponent.handleItemClick (menu.js?443e:763)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)
对于有代码洁癖的人来说,眼里是容不得半点报红的
以下是我提供的解决方案,亲测有效
在自己的router.js,或者是index.js(全局路由配置的地方)在最底部加上代码如下
1.如果没有创建VueRouter时加上以下代码
需要注意一点
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
如果已经创建了Router 则按照自己定义的名字添加以下代码
const originalPush = router.push
router.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
以上就是我解决方案的方法,如有疑问,请下方联系或者私信博主!