bug解决:Element UI侧边栏重复点击同一菜单出现报错

262 阅读1分钟

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)
};

1661778661991.png

这样问题就可以解决。