【发布时间】:2018-06-23 07:59:40
【问题描述】:
我想为不同的功能模块使用相同的布局(在 app.module.ts 中定义),每个模块都有自己的路由。还有一个单独的登录/注册布局,没有侧边菜单、页眉和页脚。到目前为止我试过这个:
//../app/app.component.html
<router-outlet></router-outlet> // here i want login and layout view.
还有一个布局组件:
//../app/layout.component.html
<header></header>
<side-menu></side-menu>
<router-outlet></router-outlet> // here i want layout views that would have side menu with them e.g. dashboard, inventory etc
<footer></footer>
仪表板路由在 app.module.ts 中,但清单和其他模块有自己的模块和路由,如下所示:
//app.module.ts
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{
path: '',
component: LayoutComponent,
children: [
{ path: '', component: DashboardOne},
{ path: 'dashboardOne', component: DashboardOne},
{ path: 'dashboardTwo', component: DashboardTwo}
],
canActivate: [AuthGuard]
}
];
@NgModule({
declarations: [
AppComponent,
DashboardOneComponent,
DashboardTwoComponent,
LoginComponent,
LayoutComponent
],
imports: [
RouterModule.forRoot(
appRoutes,
{ enableTracing: true } // <-- debugging purposes only
),
InventoryModule,
WarehouseModule,
UserModule,
],
providers: [AuthGuard],
bootstrap: [AppComponent]
})
export class AppModule { }
和其他模块:
//inventory.module.ts
const appRoutes: Routes = [
{
path: 'inventory',
//component: LayoutComponent,
children: [
{ path: '', component: InventoryOne},
{ path: 'inventoryOne', component: InventoryOne},
{ path: 'inventoryTwo', component: InventoryTwo}
],
canActivate: [AuthGuard]
}
];
@NgModule({
declarations: [
AppComponent,
InventoryOneComponent,
InventoryTwoComponent,
//LayoutComponent // want to use this layout in other modules too
],
imports: [
RouterModule.forChild(
appRoutes
),
],
providers: [],
})
export class InventoryModule { }
如果我从清单模块中删除布局组件的注释,它会重新呈现布局组件(我不希望这样),我想在每个有自己的路线的模块中使用 layoutComponent,但目前无法这样做。
【问题讨论】:
标签: angular typescript angular2-routing