vue router.push(),router.replace(),router.go()

1.router.push(location)=====window.history.pushState

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

1
2
3
4
5
6
7
8
9
10
11
// 字符串
router.push( 'home' )
 
// 对象
router.push({ path:  'home'  })
 
// 命名的路由
router.push({ name:  'user' params : { userId: 123 }})
 
// 带查询参数,变成 /register?plan=private
router.push({ path:  'register' , query: { plan:  'private'  }})

 

2.router.replace(location)=====window.history.replaceState

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

 

3.router.go(n)====window.history.go
1
2
3
4
5
6
7
8
9
10
11
12
// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1)
 
// 后退一步记录,等同于 history.back()
router.go(-1)
 
// 前进 3 步记录
router.go(3)
 
// 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)

转载于:https://www.cnblogs.com/snowhite/p/8042046.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值