路由重复问题

MuYan2020-12-01VueVue
  • 报错内容:NavigationDuplicated:Avoided redundant navigation to current location

  • 触发条件:重复点击同一个路由等类似操作

  • 主要原因:路由重复

  • 解决办法:重写 Router.prototype.push、VueRouter.prototype.replace(可选)

import Router from 'vue-router'

const router = new Router({})

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
// 重写 push 后还有问题的,可重写 replace (可选)
const VueRouterReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return VueRouterReplace.call(this, location).catch(err => err);
};
上次更新 2026/6/23 11:49:15
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.8