router/index.js
// ♥♥♥♥♥ 重写 push 和 replace ♥♥♥♥♥ =================================
// location 调往的地方(传哪些参数)
// resolve 成功回调
// reject 失败回调
let newPush = VueRouter.prototype.push; // 创建一个新的push方法替代,下面一样
let newReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location, resolve, reject) {
if (resolve && reject) {
newPush.call(this, location, resolve, reject);
} else {
newPush.call(
this,
location,
() => {},
() => {}
);
}
};
VueRouter.prototype.push = function (location, resolve, reject) {
if (resolve && reject) {
newReplace.call(this, location, resolve, reject);
} else {
newReplace.call(
this,
location,
() => {},
() => {}
);
}
};