// 两种类型history 和 hash//query要用path来引入,params要用name来引入,用法相同,最好用params,因为query相当于get,可以在url看到,params看不到,相当于post<router-link to=""><router-link><router-link :to="{name:'home',params:{plan:'5'}}"><router-link><router-link :to="{path:'home',query:{plan:'5'}}"><router-link><router-link :to="{{ path: 'home', query: { userId }}"><router-link><router-view></router-view>
router.push('home') ;// 字符串router.push({path:'home'}); // 对象router.push({path:'home',query:{userId :'5'}});// 带查询参数,变成 /home?userId =5 ,获取 this.$route.query.userId router.push({ path: 'home', query: { userId }});{ path:"/home", name:"home", component:home, title:"home", redirect:"home", children:[],}//路由重定向router.redirect({ '/': '/home'})
<a v-link="'home'">Home</a><a v-link="{ path: 'home' }">Home</a><a v-link="{ name: 'detail', params: {id: '01'} }">Home</a><a v-link="{ path: 'home', query: {id: '01'} }">Home</a>
//对象,包含路由中查询参数的键值对。例如,对于 /home/news/detail/01?favorite=yes ,会得到$route.query.favorite == 'yes'$route.query
//参数to指的要跳到的路由,to.name是要跳到的路由的namerouter.beforeEach((to,from,next)=>{ document.title = to.title; if(store.state.user.id !="" && to.name != "login"){ next() }else{ next("/login") }})