1、區別:
this.$router是全局路由器對象 this.$route是當前激活的路由對象,包含了當前的路由信息。
console.log(this.$route); { fullPath:'/home' //包含查詢參數和 hash 的完整路徑 path:'', //當前路由路徑,絕對路徑 name:'Home', meta:{auth:true}, //是否需要登錄 hash:'', params:{}, query:{id:1} //表示 URL 查詢參數,相當於/home?id=1 matched:?? }
1.字符串 this.$router.push('/home') 2.對象 this.$router.push({path:'home'}) 3.命名的路由 this.$router.push({name:'home',params:{id:1}}) 4.帶查詢參數 this.$router.push({path:'home',query:{id:1}})
1.聲明式:<router-link :to="">
2.編程式:this.$router.push();
4、path:'name' 和 path:'/name' 區別:
假如當前路徑是home
this.$router.push('/name') => /home/name this.$router.push('name') => /name
