【发布时间】:2019-03-24 00:22:27
【问题描述】:
我正在尝试在我的 Angular 应用程序上实现路由功能,并取得了部分成功。路由适用于我的应用程序的主容器(路径,没有出口属性)。
我遇到的问题是我正在尝试为侧边栏实现第二个路由器出口(出口属性称为“侧边栏”的路径)。它不工作。
我的路径如下:
const appRoutes: Routes = [
{ path: '', component: WorkspaceAreaComponent }, // localhost:4200/workspace
{ path: 'workspace', component: WorkspaceAreaComponent }, // localhost:4200/workspace
{ path: 'reports', component: ReportsAreaComponent, children: [
{ path: '', component: ActiveProjectStatisticsComponent },
{ path: 'active-project-stats', component: ActiveProjectStatisticsComponent },
{ path: 'productivity-tracking', component: ProductivityTrackingComponent },
] },
{ path: 'templates', component: TemplatesAreaComponent, children: [
{ path: '', component: TemplateSectionsComponent },
{ path: 'email', component: TemplateEmailComponent }
] },
{ path: '', component: TemplatesComponent, outlet: 'sidebar' },
{ path: 'templates', component: TemplatesComponent, outlet: 'sidebar' },
{ path: 'reports', component: ReportsComponent, outlet: 'sidebar' }
];
主容器的组件如下所示:
<div class="mainContainer">
<router-outlet></router-outlet>
</div>
侧边栏的组件如下所示:
<div class="asideBox">
<router-outlet name="sidebar"></router-outlet>
</div>
包含两者的父组件模板如下:
<app-header></app-header>
<div class="bodyContainer">
<div *ngIf="!isOrganiserPage; else organiserPane" class="flexResponsive768">
<aside class="width20">
<!-- SIDEBAR COMPONENT -->
<app-sidebar></app-sidebar>
</aside>
<!-- MAIN COMPONENT -->
<main class="width80" app-main-pane>
</main>
</div>
<ng-template #organiserPane>
<main></main>
</ng-template>
</div>
<app-right-pane></app-right-pane>
<app-modals></app-modals>
有人可以帮我解决这个问题吗?我已经尝试通过教程来解决这个问题,但运气不佳。
谢谢。
【问题讨论】:
标签: angular angular2-routing angular-routing angular-template router-outlet