怎么解决ElementUI导航栏重复点菜单报错问题

发布时间:2022-08-01 09:27:02 作者:iii
来源:亿速云 阅读:151

本文小编为大家详细介绍“怎么解决ElementUI导航栏重复点菜单报错问题”,内容详细,步骤清晰,细节处理妥当,希望这篇“怎么解决ElementUI导航栏重复点菜单报错问题”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

ElementUI 导航栏重复点菜单报错

在使用ElementUI中的导航时,默认情况下如果重复点击某选项,会报错。

element-ui.common.js?b705:3354 Error: Avoided redundant navigation to current location: “/home/home1”.
at createRouterError (vue-router.esm.js?8c4f:2060)
at createNavigationDuplicatedError (vue-router.esm.js?8c4f:2033)
at HashHistory.confirmTransition (vue-router.esm.js?8c4f:2182)
at HashHistory.transitionTo (vue-router.esm.js?8c4f:2123)
at HashHistory.push (vue-router.esm.js?8c4f:2582)
at VueRouter.push (vue-router.esm.js?8c4f:2903)
at VueComponent.routeToItem (element-ui.common.js?b705:3381)
at VueComponent.handleItemClick (element-ui.common.js?b705:3348)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)

如图所示:

怎么解决ElementUI导航栏重复点菜单报错问题

可以在router的配置文件中(router -> index.js)加上下面这句话,注意位置:

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

问题即可解决。

ElementUI 菜单导航重定向报错处理

当我们使用ElementUI中的菜单导航时,配置好菜单路由后,重复点击同一个菜单项会报错,如下:

Error: Avoided redundant navigation to current location: “/xxx”.

还有一个错误是,我配置了一个路由守卫,当用户还没有登录的时候,点击菜单项时,如果没有登录则会跳转至登录页面进行登录,这时页面可以正常跳转但是也会报出错误,如下:

Error: Redirected when going from “/xxx” to “/yyy” via a navigation guard.

解决第一个问题的方法,如下:

import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

在引入vue-router的地方加入此代码块,就能解决重复点击同一菜单项的报错,但是神奇的是,我的第二个问题也因此解决了。

读到这里,这篇“怎么解决ElementUI导航栏重复点菜单报错问题”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 解决Azure automation 报错问题
  2. elementUI 动态渲染三级菜单

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

elementui

上一篇:Python tkinter多选按钮控件Checkbutton怎么使用

下一篇:ASP.NET中加密和解密怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》