关于this.$router.push、replace、go的用法和区别

1、this.$router.push

this.$router.push
跳转到指定url路径,并想history栈中添加一个记录,点击后退会返回到上一个页面

1.跳转到指定url路径,并想history栈中添加一个记录,点击后退会返回到上一个页面
2.声明式:< router-link :to = “…” >
3.编程式:< router.push(…) > // 该方法的参数可以是一个字符串路径,或者一个描述地址的对象

在这里插入代码片// 字符串
this.$router.push('index') 

// 对象
this.$router.push({path: 'login-pw'})

// 带参数
this.$router.push({path: 'login-pw', query: {'account': this.account.account}})

// 跳转后的页面获取参数
this.account.account = this.$route.query.account

2、this.$router.replace

跳转到指定url路径,但是history栈中不会有记录,点击返回会跳转到上上个页面

1.跳转到指定的URL,替换history栈中最后一个记录,点击后退会返回至上一个页面。(A----->B----->C 结果B被C替换 A----->C)
2.设置replace属性(默认值:false)的话,当点击时,会调用router.replace(),而不是router.push(),于是导航后不会留下history记录。
3.即使点击返回按钮也不会回到这个页面。加上replace: true时,它不会向 history 添加新纪录,而是跟它的方法名一样——替换当前的history记录。

// 声明式
<reouter-link :to="..." replace></router-link>
// 编程式:
router.replace(...)
// push方法也可以传replace
this.$router.push({path: '/homo', replace: true})

      this.$router.replace({
        name: this.pageFrom,
        params: this.formData
      })
 onConfirm: () => {
          this.$router.replace('/TravelManage')
        }

3、this.$router.go(n)

向前或者向后跳转n个页面,n可为正整数或负整数

1.向前或者向后跳转n个页面,n可为正整数或负整数

2.this.$router.go(1) // 类似history.forward()

3.this.$router.go(-1) // 类似history.back()

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

都挺好,刚刚好

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值