Skip to main content

路由跳转

路由跳转分为声明式和编程式两种

使用 router-link 组件来导航,通过传入 to 属性指定链接(router-link 默认会被渲染成一个 a 标签)

展示页面渲染在 router-view 里面

编程式(router)

采用这种方式一般需要配合 VueRouter 并调用,常用跳转方法为:

  • this.$router.push() 跳转到指定的 url,但这个方法会向 history 栈添加一个记录,点击后退会返回到上一个页面。
  • this.$router.replace 同样是跳转到指定的 url,但是这个方法不会向 history 里面添加新的记录,点击返回,会跳转到上上一个页面,上一个记录是不存在的。

注意:获取参数的时候是 $route,跳转和传参的时候是 $router