6-1 配置子路由

  1. //Tips:在主路由的chilren属性中去配置
  2. const routes = [
  3. {
  4. path: '/films',
  5. name: 'films',
  6. component:()=>import('../views/Films.vue'),
  7. children:[
  8. {
  9. path:'nowPlaying',
  10. component:()=>import('../views/NowPlaying.vue')
  11. },{
  12. path:'comingSoon',
  13. component:()=>import('../views/ComingSoon.vue')
  14. }
  15. ]
  16. }
  17. ]

6-2 在主路由对应的组件中去设置router-view

  1. 目的:router-view去装载这些子路由。router-view本质上就是一个动态组件。
  2. //在Films.vue组件中去配置
  3. <router-view></router-view>

七、路由重定向

  1. const router = new VueRouter({
  2. routes: [
  3. { path: '/a', redirect: '/b' }
  4. ]
  5. })

八、v