Vue项目中重复点击路由报错Avoided redundant navigation to current location
在vue项目中,点击侧边栏,不同路由之间切换正常。
但是在重复点击同一菜单后会报错:
Uncaught (in promise) Error: Avoided redundant navigation to current location:
网上找到了一种解决办法:
在 router 文件夹下的 index.js 中添加下面的代码。
const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) }
如下图,即可解决问题,原理暂时还没理解,在这里暂做下记录。