>[info]子路由的配置方式与路由配置一样,区别在于子路由嵌套在父路由里面,子路由使用children声明 ``` //路由配置 const routes: Routes = [ { path: 'parent', component: ParentComponent, data:{ parent:'parent', child:'child' }, children: [ //子路由配置,嵌套在父路由中,使用children声明 { path: "child", component: ChildComponent } ] }, { path: '', //默认打开的路由 redirectTo: '', /*重定向*/ pathMatch: 'full' }, { path: '**', /*匹配任意URL,当匹配不到定义的路由时跳转到404组件*/ component: PageNotFoundComponent } ]; ``` >[info]使用子路由 ``` //在父组件中添加路由出口即可 <a routerLink="child" routerLinkActive="router-link-active">跳转到child组件</a> <router-outlet></router-outlet> ```