- 错误信息
NavigationDuplicated: Avoided redundant navigation to current location: "/menu".
-
图片补充
-
错误信息翻译
避免冗余导航到当前位置Avoided redundant navigation to current location
-
分析导致原因
这个报错是出现在我实现菜单组件中的。由于没有限制,每个菜单栏可以不停的点击,以至于不停的跳本界面。 -
解决方案
- 他人的方案(我个人不建议):
- 添加
this.$router.push('/location').catch(err =>{console.log(err)})
打印报错信息,来避免报红。
- 添加
- 个人方案:
- 点击function记录一个flag, 每次点击先判断点击的菜单栏是否和flag中的相同,如果相同直接return掉,不同则跳转。这样就避免不停的点击跳同一个页面。
- 代码demo:
- 他人的方案(我个人不建议):
data() {
return {
flag: '
}
}
toRouter(item) {
if (item.path === this.flag) {
return
} else {
this.flag = item.path
this.$router.push({
path: '/xxxx'
})
}
}
- 寄语
- 个人愚见,望指点!