markdown在线编辑链接

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