Skip to content

编程式路由导航

1.作用:不借助 <router-link> 实现路由跳转,让路由跳转更加灵活

2.具体编码:

JavaScript
// 两种跳转方式
pushShow(m) {
  this.$router.push({
    name: "xiangqing",
    query: {
      id: m.id,
      title: m.title,
    },
  });
},
replaceShow(m) {
  this.$router.replace({
    name: "xiangqing",
    query: {
      id: m.id,
      title: m.title,
    },
  });

历史记录的前进后退

JavaScript
back(){
  this.$router.back()
},
forward(){
  this.$router.forward()
},
go(){
  // 正数为前进,负数为后退
  this.$router.go(3)
}