【无标题】

文章提供了在VueRouter的index.js中修改push和replace方法的代码片段,以解决在ElementUI导航栏中遇到的3.0版本以上路由重复跳转的问题。通过添加对res和rej参数的检查,确保在无回调函数时正确执行路由操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
解决方案:在router的index.js文件夹中添加如下代码

Vue.use(VueRouter)
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复跳转一个路径报错问题
let originPush = VueRouter.prototype.push
let originReplace = Vue.prototype.originReplace

VueRouter.prototype.push = function (location,res,rej) {
    if (res && rej ) {
        originPush.call(this,location,res,rej)![在这里插入图片描述](https://img-blog.csdnimg.cn/6269dc1bdba94ca88480f4a642496a4d.jpeg#pic_center)

    } else {
        originPush.call(this,location,()=>{},()=>{})
    }
}

VueRouter.prototype.replace = function(location ,res,rej) {
    if (res && rej) {
        originReplace.call(this,location,res,rej)
    } else {
        originReplace.call(this,location,() => {},() => {})
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值