0
点赞
收藏
分享

微信扫一扫

vue项目报错 Navigating to current location (XXX) is not allowed

芒果六斤半 2021-09-29 阅读 121
日记本

今天写项目时,点击左侧导航栏时,总会反复报这样的错误,message: "Navigating to current location (XXX) is not allowed"。


仔细研究了下发现是在当前页面又点击了当前页面对应导航菜单,造成报错的原因是当前访问的路由相同,查查资料发现,需要重写路由的push方法

解决方法如下:

// 重写路由的push方法

import Router from 'vue-router'

const routerPush = Router.prototype.push

Router.prototype.push = function push(location) {

           return routerPush.call(this, location).catch(error=> error)

}

解决了,嗯,开心~

后续

Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/Operation/syncorder".

这个错误也可以用这种方法解决

举报

相关推荐

0 条评论