Angular 2 - Submodule routing and nested

后端 未结 3 1760
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 08:46

I\'m looking for a solution with Angular 2 for the scenario explained below:

In this scenario, the top-nav contains links to load submodules and sub-nav has

3条回答
  •  不知归路
    2020-12-07 09:44

    Use:

    RouterModule.forChild()
    ...
    
    ...
    [routerLink]="[{ outlets: { sub: [subRouteName] } }]"
    

    Full example:

    HTML

    app.module.ts

    imports: [
    ...
        RouterModule.forChild([
          {
            path: 'registers',
            component: RegistersComponent,
            children: [
              {path: 'vehicles', component: VehiclesComponent, outlet: 'sub'},
              {path: 'drivers', component: DriversComponent, outlet: 'sub'},
              {path: 'bases', component: BasesComponent, outlet: 'sub'},
              {path: 'lines', component: LinesComponent, outlet: 'sub'},
              {path: 'users', component: UsersComponent, outlet: 'sub'},
              {path: 'config', component: ConfigComponent, outlet: 'sub'},
              {path: 'companies', component: CompaniesComponent, outlet: 'sub'}
            ],
            canActivate: [AuthGuard]
          }
        ]),
    ...
    

提交回复
热议问题