从根本上解决问题
// 先吧VueRouter原型对象上的push保存一份
let originPush=VueRouter.Prototype.push;
let originReplace=VueRouter.Prototype.Replace;
// 重些push|replace
// 第一个参数:高速原来的push方法,你往哪里跳转(传递那些参数)
// 第二个参数是成功的回调
// 第三个参数是失败的回调 解决编程试路由导航点多报错的情况解决方法
VueRouter.prototype.push = function(location,resolve,reject){
if(resolve && reject)
// call和apply区别:相同点,都可以调用函数一次,都可以篡改函数的上下文一次
// 不同点:call与appl传递参数:call传递参数用逗号隔开 ,apply方法执行。传递数组
originPush.call(this,location,resolve,reject)
else{
originPush.call(this,location,()=>{},()=>{})
}
}
VueRouter.prototype.replace = function(location,resolve,reject){
if(resolve && reject)
originReplace.call(this,location,resolve,reject)
else{
originReplace.call(this,location,()=>{},()=>{})
}
}
{
// 重定向,在项目跑起来的时候立马让他定向到首页
path:'*',
redirect:'/Home'
}