第十七:嵌套路由

4.7. 【嵌套路由】

  1. 编写News的子路由:Detail.vue

  2. 配置路由规则,使用children配置项:

    const router = createRouter({
      history:createWebHistory(),
      routes:[
        {
          name:'zhuye',
          path:'/home',
          component:Home
        },
        {
          name:'xinwen',
          path:'/news',
          component:News,
          children:[
            {
              name:'xiang',
              path:'detail',
              component:Detail
            }
          ]
        },
        {
          name:'guanyu',
          path:'/about',
          component:About
        }
      ]
    })
    export default router
  3. 跳转路由(记得要加完整路径):

    xxxx
    
    xxxx
  4. 记得去Home组件中预留一个

你可能感兴趣的:(前端,前端,javascript)