Vue 路由报错 NavigationDuplicated: Navigating to current location is not allowed 解决方法

2026-06-05 122 浏览 0 评论

使用 Vue 2.x 开发项目,路由当然也是用的官方的路由,一直也是挺好用的,但是如果是相同的页面,也就是重复点击就会报错:

vue.esm.js?efeb:628 [Vue warn]: Error in v-on handler (Promise/async): "NavigationDuplicated: Navigating to current location ("/register?type=lawyer") is not allowed"

这种情况改写一下路由的 push 方法就可以了,将要跳转的 location 的路由放进去。

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}


发布评论

发布评论前请先 登录
0 评论
点赞
收藏

评论列表 0

暂无评论