路由重复问题
报错内容: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);
};
Powered by Waline v2.15.8