解决 this.$router.push 多次执行时报 navigationDuplicated 错误

在 Router / index.js (路由配置文件) 中:

 /* 1. 备份push方法  */
let originPush = VueRouter.prototype.push
console.log(originPush);

/* 2. 重写push方法  */
/* 
  location:跳转地址,传递的参数
  resolve:成功时回调
  reject:失败时回调
*/
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  } else {
    originPush.call(this, location, () => {}, () => {})
  }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
this.$router.push可以实现多次跳转。你可以在一个方法或事件中多次调用this.$router.push来实现多次跳转。每次调用this.$router.push都会将新的路由添加到路由历史记录中,并导航到相应的页面。例如,你可以这样使用this.$router.push来实现多次跳转: ```javascript this.$router.push('/home/first'); this.$router.push('/home/second'); this.$router.push('/home/third'); ``` 这样就会依次跳转到'/home/first'、'/home/second'和'/home/third'页面。每次跳转都会将新的路由添加到路由历史记录中,并在页面中显示相应的内容。 #### 引用[.reference_title] - *1* [Vue中this.$router.push(参数) 实现页面跳转](https://blog.csdn.net/weixin_57607714/article/details/126649338)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [vue的跳转方式——window.open & router-link标签 & this.$router.push跳转 & this.$router.replace跳转 & ...](https://blog.csdn.net/weixin_44867717/article/details/120503404)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值