vue-router 路由跳轉方法
- router-link
<router-link to="/">首頁</router-link> |
<router-link to="/blog">博客</router-link> |
<router-link to="/video">視頻</router-link> ||
- this.$router.push()
<button @click="router_p">點擊跳轉router-push</button>
methods:{
router_p(){
this.$router.push('/login')
}
}
- this.$router.replace() 同上push
- this.$router.go(n)
向前或者向后跳轉n個頁面,n可為正整數或負整數
ps : 區別
- this.$router.push
跳轉到指定url路徑,並想history棧中添加一個記錄,點擊后退會返回到上一個頁面
- this.$router.replace
跳轉到指定url路徑,但是history棧中不會有記錄,點擊返回會跳轉到上上個頁面 (就是直接替換了當前頁面)
- this.$router.go(n)
向前或者向后跳轉n個頁面,n可為正整數或負整數