如果有可能有多个路由器插座,我没有任何工作代码,但假设我在 AppComponent
中的父 <router-outlet>
中有登录页面 . 登录后,我必须在父 <router-outlet>
中显示 MyHomeComponent
. 现在,假设在 MyHomeComponent
我想要一个孩子 <router-outlet>
,其中我想在用户点击 Inbox
, Outbox
和 Starred
链接时显示 inbox
消息, outbox
消息, starred
消息 . 请帮我找到这个问题的答案
AppComponent <router-outlet></router-outlet>
,
HomeComponent
<a routerLink="/xyz">Inbox</a>
<a routerLink="/abc">Outbox</a>
<router-outlet name='outlet1'></router-outlet>
我的路线路径
{ path: 'login', component: LoginComponent},
{ path: '', component: LoginComponent },
{ path: 'user', children:[
{ path: ':name',children:[
{path:'abc', component: InboxComponent, outlet: 'outlet1' },
{path:'xyz', component: OutboxComponent, outlet:'outlet1' }
] }]},
{ path: '**', component: PageNotFoundComponent }
1 回答
每个路由可以有一个主
<router-outlet>
,另外一个名为<router-outlet name="abc">
. 寻址这些命名出口的路线称为辅助路线 . 这些路线反映在()
中的URL中,如/crisis-center(aux:chat;open=true)"
也可以看看
https://angular.io/docs/ts/latest/guide/router.html
https://angular.io/docs/ts/latest/api/router/index/Routes-type-alias.html
https://angular.io/docs/ts/latest/api/router/index/Router-class.html
Angular2 multiple router-outlet in the same template