重复跳转相同路由时控制台会报错:
Avoided redundant navigation to current location: “/xxx”,
此时需要对router文件进行修改
import Router from 'vue-router';
// push
const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err);
};
// replace
const originalReplace = Router.prototype.replace;
Router.prototype.replace = function push(location, onResolve, onReject) {
if (onResolve || onReject) {
return originalReplace.call(this, location, onResolve, onReject);
}
return originalReplace.call(this, location).catch(err => err);
};