【发布时间】:2019-09-03 01:54:09
【问题描述】:
我正在尝试在 Angular Material 弹出对话框中使用 <router-outlet></router-outlet>。
但是,router-outlet 部分不会渲染任何内容,也不会将任何内容记录到控制台。
如果我将<router-outlet></router-outlet>添加到弹出对话框的组件的HTML内容中(ContextBuyerPinComponent),那么它可以正常工作。
路线如下所示:
const demoRoutes: Routes = [
{
path: 'demo',
children: [
{ path: 'register-email', component: RegisterEmailComponent },
{
path: 'context-buyer-pin',
component: ContextBuyerPinComponent,
children: [
{ path: 'services', component: ContextPinServicesComponent },
{ path: 'emails', component: ContextPinEmailsComponent },
{ path: 'details', component: ContextPinDetailsComponent }
]
}
]
}
];
对话框通过 ContextBuyerPinComponent 打开,如下所示:
this.matDialog.open(ContextBuyerPinDialogComponent, this.config);.
而ContextBuyerPinDialogComponent HTML如下:
<mat-toolbar color="primary" class="mat-elevation-z4">
<app-tab [icon]="'room_service'" [displayType]="getDisplayType()" [caption]="'Local Services'"
routerlink="demo/context-buyer-pin/services">
</app-tab>
<app-tab [icon]="'email'" [displayType]="getDisplayType()" [caption]="'Emails'"
routerlink="demo/context-buyer-pin/emails">
</app-tab>
<app-tab [icon]="'map-pin'" [displayType]="getDisplayType()" [isSvg]="true" [caption]="'Pin Details'"
routerlink="demo/context-buyer-pin/details">
</app-tab>
</mat-toolbar>
<router-outlet></router-outlet>
我尝试使用命名路由器插座作为替代方案,但没有成功。
工具栏正在使用 app-tab 组件,并且正在使用运行正常的 routerLinkActive 指令,因此看起来路由正在运行。
我如何让它工作?
【问题讨论】:
-
这个问题在 stackblitz stackblitz.com/edit/angular-material2-issue-dehbgc987654321@ 上有说明
-
一个线索可能是我需要在 context-buyer-pin.component.ts 第 18 行添加一个守卫。如果没有这个,它会使浏览器崩溃,显然进入一个循环。
标签: angular angular7 router-outlet angular-material-7