以角度同时加载多个子组件

时间:2018-01-14 06:37:39

标签: angular angular-ui-router angular2-routing angular4-router

我希望我的主页显示侧边栏菜单中的预选选项。我该怎么办?就像我想要有人登陆主页一样,他应该出现在主页>侧边栏>关于

const appRoutes: Routes = [
  {
    path: '', component: HomeComponent, children: [{
      path: 'sidebar', component: SidebarComponent, children: [
        { path: 'about', component: AboutComponent },
        { path: 'clients', component: ClientsComponent },
        { path: 'services', component: ServicesComponent },
        { path: 'contact', component: ContactComponent },
        { path: 'datatable', component: DataComponent }
      ]
    }]
  }

1 个答案:

答案 0 :(得分:0)

您可以使用空路径 redirectTo 属性来实现您的目标。

const appRoutes: Routes = [
  {
    path: '', component: HomeComponent, children: [
    { path: '', redirectTo: '/sidebar', pathMatch: 'full' },
    {
      path: 'sidebar', component: SidebarComponent, children: [
        { path: '', redirectTo: '/about', pathMatch: 'full' },
        { path: 'about', component: AboutComponent },
        { path: 'clients', component: ClientsComponent },
        { path: 'services', component: ServicesComponent },
        { path: 'contact', component: ContactComponent },
        { path: 'datatable', component: DataComponent }
      ]
    }]
  }

您可以参考redirecting routeschild route configuration的Angular文档。