下面的僞代碼描述了我的組件樹結構。在Angular 2中使用router-outlet
<app-root>
<router-outlet name="main">
<Home-component>
<a routerLink="about">About</a> //
<router-outlet name="home"> </<router-outlet>
</Home-component>
</<router-outlet>
</app-root>
當用戶點擊「關於」鏈接時,關於組件顯示在 「主」路由出口,但我的本意是在「家」的路由器出口, 需要修改什麼來顯示它實現這一目標。
「app-root」組件和「Home-component」是根模塊的一部分,「AboutComponent」是特徵模塊的一部分。
根模塊路由如下..
RouterModule.forRoot([
{path:'' , component:LoginComponent },
{path:'home' , component:HomeComponent}
]),
和功能模塊路由如下...
RouterModule.forChild([
{path:'about' , component:AboutComponent }
])
你需要將''''''路由配置成'home'路由的子節點。 – ranakrunal9
首先配置路由,然後嘗試'' –
查看此答案[http://stackoverflow.com/a/40477582/7045253](http://stackoverflow.com/a/40477582/7045253) –