主要问题:有没有办法显示到父路由器出口的子路由?
考虑Angular.io路由器指南中的这个例子。
主要路线片段:
const appRoutes: Routes = [
...
{
path: 'admin',
loadChildren: 'app/admin/admin.module#AdminModule',
canLoad: [AuthGuard]
},
{
path: 'crisis-center',
loadChildren: 'app/crisis-center/crisis-center.module#CrisisCenterModule',
data: { preload: true }
},
....
];
主要组件片段:
@Component({
selector: 'app-root',
template: `
<h1 class="title">Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a>
<a routerLink="/superheroes" routerLinkActive="active">Heroes</a>
<a routerLink="/admin" routerLinkActive="active">Admin</a>
...
</nav>
<router-outlet></router-outlet>
`
})
危机中心路线片段:
const crisisCenterRoutes: Routes = [
{
path: '',
component: CrisisCenterComponent,
children: [
{
path: '',
component: CrisisListComponent,
children: [
{
path: ':id',
component: CrisisDetailComponent,
...
},
{
path: '',
component: CrisisCenterHomeComponent
}
]
}
]
}
];
危机列表组件片段:
@Component({
template: `
<ul class="items">
<li *ngFor="let crisis of crises$ | async"
[class.selected]="crisis.id === selectedId">
<a [routerLink]="[crisis.id]">
<span class="badge">{{ crisis.id }}</span>{{ crisis.name }}
</a>
</li>
</ul>
<router-outlet></router-outlet>
`
})
CrisisDetailComponent 片段:
@Component({
template: `
<div *ngIf="crisis">
<h3>"{{ editName }}"</h3>
...
</div>
`
})
这个路由器的输出是这样的:
所以。我想说的是,当您单击Dragon Burning Cities时,而不是在下面显示它,为什么不直接在 CrisesListComponent 级别显示它?
我能想到的就是在 CresesListComponent 中像这样使用* ngIf:
@Component({
template: `
<ul class="items" *ngIf="a list is selected hide this!!!">
<li *ngFor="let crisis of crises$ | async"
[class.selected]="crisis.id === selectedId">
<a [routerLink]="[crisis.id]">
<span class="badge">{{ crisis.id }}</span>{{ crisis.name }}
</a>
</li>
</ul>
<router-outlet></router-outlet>
`
})
是否想在此父路由出口上将子路由器设置为此显示?
谢谢。我希望我把我的问题说清楚了。