vue-router的push和replace的区别


methods: {
    gotoMenu(){
      //跳转到上一次浏览的页面  this.$router.go(-1)
      this.$router.go(-1)
 
      //指定跳转的地址 this.$router.replace('/menu')
      this.$router.replace('/menu')
 
      //指定跳转的路由的名字下 this.$router.replace({name:'menu'})
      this.$router.replace({name:'menu'})
 
      //通过push进行跳转
      this.$router.push('/menu')
    }
  },

路由跳转的值传递 


1.
传递
this.$router.push({name:'路由name',params:{search:value}})
获取
this.$route.params.search
2.通过path携带的参数
传递
this.$router.push({ path: '路由url'+id})
获取
 this.$route.params.id
注意此方法使用时需在路由path中配置   /:id
{
 path: 'myadmexp/details/:id'
}
3.通过query来传递参数,使用此方法传递的参数会出现在url地址中
传递
this.$router.push({ name:'name' ,query:{id:code,id2:code2}});
获取
this.$route.query.id;
this.$route.query.id2;

1.this.$router.push()

描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面。

2.this.$router.replace()

描述:同样是跳转到指定的url,但是这个方法不会向history里面添加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。

3.this.$router.go(n) 相对于当前页面向前或向后跳转多少个页面,类似 window.history.go(n)。n可为正数可为负数。正数返回上一个页面

router.go(n) 
这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)

router.push(location) 
想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。

router.replace(location) 
跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值