可脱离<router-link :to=“url”>……</router-link>标签
使用this.$router中的 push 或 replace 方法实现俩种跳转方式即:追加历史记录,覆盖顶层历史记录
例如:点击按钮跳转
<button @click="pushShow(message)">push查看</button>
<button @click="replaceShow(message)">replace查看</button>
methods: {
pushShow(message){
this.$router.push({
name: 'HomeMessageDetail',
query: {
id: message.id,
title: message.title
}
})
},
replaceShow(message){
this.$router.replace({
name: 'HomeMessageDetail',
query: {
id: message.id,
title: message.title
}
})
}
}
router 中的back()、forward()、go()
back:后退一步
forward:前进一步
go:前进或后退指定步数正数为前进 负数为后退
例如
<button @click="back">后退</button>
<button @click="forward">前进</button>
<button @click="go">go-2</button>
methods: {
back(){
this.$router.back()
},
forward(){
this.$router.forward()
}
go(){
this.$router.go(-2)
}
}