美文网首页前端开发程序员
vue router.push(),router.replace

vue router.push(),router.replace

作者: itsmyturn | 来源:发表于2019-04-03 14:17 被阅读3次

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

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

// 字符串
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

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

// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1)
 
// 后退一步记录,等同于 history.back()
router.go(-1)
 
// 前进 3 步记录
router.go(3)
 
// 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)

相关文章

  • vue router.push(),router.replace

    1.router.push(location)=====window.history.pushState 说明:想...

  • 编程式导航

    明确 router.push router.replace router.go router.forward ro...

  • 2018-12-06

    vue的写法: $router.push('name'); $router.push( {path:'name'}...

  • vur-router知识点总结

    编程式导航 router.push 注意:在 Vue 实例内部,你可以通过 router.push。想要导航到不同...

  • vue 中query 和params传参

    跳转到home.vue页面:this.$router.push({name:'Home'}) 或者this.$ro...

  • vue页面跳转 vue生命周期

    1.vue页面跳转 // 字符串this.$router.push('/home/first') // 对象thi...

  • Vue

    1.函数路由跳转:this.$router.push('detail') 2. SEO 思路处理 Vue 单页面 ...

  • vue -router传参

    vue路由用params传参时需要用到name this.$router.push({'name':'','par...

  • this.$router与this.$route的区别

    this.$router是Vue-Router的实例,需要导航到不同路由则用this.$router.push方法...

  • Vue笔记

    1.vue文件之间使用路由跳转传值: this.$router.push({ path:'要跳转的页面路径',...

网友评论

    本文标题:vue router.push(),router.replace

    本文链接:https://www.haomeiwen.com/subject/oztzbqtx.html