1.问题描述
在使Element UI实现侧边栏效果后,如果重复点击同一菜单项会在控制台出现如下报错:
报错内容是
Uncaught (in promise) NavigationDuplicated {_name: 'NavigationDuplicated', name: 'NavigationDuplicated', message: 'Navigating to current location ("/Mall") is not allowed', stack: 'Error\n at new NavigationDuplicated (webpack-int…node_modules/vue/dist/vue.runtime.esm.js:3467:26)'}
通过查阅资料,发现一个解决方案:
2.解决方案
在vue-router的配置文件中加入如下的代码
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
};
这样问题就可以解决。