编程式路由导航 API

本文详细介绍了Vue.js中的编程式路由导航API,包括使用`router.push`进行页面跳转,`router.replace`实现无历史记录的跳转,以及`router.back`和`router.go`进行前进和后退操作。这些方法对于理解和控制Vue应用的页面流至关重要。

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

this.router.push(path)相当于点击路由链接(后退1步,会返回当前路由界面)this.router.push(path) 相当于点击路由链接(后退1步,会返回当前路由界面) this.router.push(path)(退1,)this.router.replace(path) 用新路由替换当前路由(后退1步,不可返回到当前路由界面)
this.router.back()后退回上一个记录路由this.router.back() 后退回上一个记录路由 this.router.back()退this.router.go(n) 参数 n 指定步数
this.router.go(−1)后退回上一个记录路由this.router.go(-1) 后退回上一个记录路由 this.router.go(1)退this.router.go(1) 向前进下一个记录路由

  <ul >
          <li v-for="(tech,index) in techArr" :key="tech.id">
              <span>{{tech.title}}</span>
              <button @click="pushTech(tech.id)" class="btn  btn-default btn-xs">查看(Push)</button>&nbsp;
              <button @click="replaceTech(tech.id)" class="btn btn-default btn-xs">查看(replace)</button>
          </li>

          <button @click="$router.back()">后退</button>
          <button @click="$router.go(-1)">go后退</button>
          <button @click="$router.go(1)">前进</button>
      </ul>

           pushTech(id){
                this.$router.push(`/news/tech/detail/${id}`)
            },
            replaceTech(id){
                this.$router.replace(`/news/tech/detail/${id}`)
            },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值