vue 之this.$router.push、replace、go的區別


一、this.$router.push

說明:跳轉到指定URL,向history棧添加一個新的記錄,點擊后退會返回至上一個頁面

使用:

this.$router.push('/index')
this.$router.push({path:'/index'})
this.$router.push({path:'/index',query:{name: '123'}})
this.$router.push({name:'index',params:{name:'123'}})

  

二、this.$router.replace

說明:跳轉到指定URL,替換history棧中最后一個記錄,點擊后退會返回至上上一個頁面

使用:同push

 

三、this.$router.go(n)

說明:類似window.history.go(n),向前或向后跳轉n個頁面,n可正(先后跳轉)可負(向前跳轉)

使用:

this.$router.go(1)    //類似history.forward()

this.$router.go(-1)   //類似history.back()

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM