Vue路由跳轉的四種方式用法及區別
點擊打開視頻講解更加詳細
一、router-link
<router-link :to="{name:'home'}">
<router-link :to="{path:'/home'}"> //name,path都行, 建議用name
// 注意:router-link中鏈接如果是'/'開始就是從根路由開始,如果開始不帶'/',則從當前路由開始,
二、this.$router.push()
this.$router.push('/home')
this.$router.push({name:'home'})
this.$router.push({path:'/home'})
三、this.$router.replace()
this.$router.replace('/home')
this.$router.replace({name:'home'})
this.$router.replace({path:'/home'})
四、this.$router.go(n)
this.$router.go(n)
向前或者向后跳轉n個頁面,n可為正整數或負整數
ps : 區別
- this.$router.push
跳轉到指定url路徑,并想history堆疊中添加一個記錄,點擊后退會回傳到上一個頁面 - this.$router.replace
跳轉到指定url路徑,但是history堆疊中不會有記錄,點擊回傳會跳轉到上上個頁面 (就是直接替換了當前頁面) - this.$router.go(n)
向前或者向后跳轉n個頁面,n可為正整數或負整數
若對您有幫助,請點擊跳轉到B站一鍵三連哦!感謝支持!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/503476.html
標籤:其他
上一篇:# JavaScript 物件
下一篇:# JavaScript 函式
