升级vue-router至3.1以后版本,导航组件重复点击报错 NavigationDuplicated
或者报错 Uncaught (in promise) Error: Avoided redundant navigation to current location
如下:
方法一,将vue-router版本锁在3.1版本以下
// 卸载原来的vue-router
npm uninstall vue-router
// 安装指定版本(3.1以下)的vue-router,我选择装3.0.6
npm i vue-router@3.0.6
方法二,使用router.push时,请进行catch处理,将这个错误捕获。(这里是更改了原型上的push方法,进行了catch处理)
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error => error);
};