我想知道,這是在做NG-內容VS路由器出口在角2
我的更好的方法。在父組件中使用ng-content,並在稍後創建子組件時,使子組件包含在父組件的選擇器中。
例如:我想創建一個父視圖作爲組件。 a。 LandingComponet(Parent):
<div>
Website Landing view
....
...
<ng-content></ng-content>
....
...
<footer></footer>
...
</div>
b。 LoginComponent或RegisterComponent(子組件)
<app-landing>
<div>
Login view or Register view
...
</div>
</app-landing>
c。添加單獨的路線的所有兒童組件
{ path: '', component: LandingComponent },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent }
II。在父組件中使用router-outlet,並在路由文件中創建多個子路由。 例如:我想創建一個父視圖作爲組件。 a。 LandingComponet(Parent):
<div>
Website Landing view
....
...
<router-outlet></router-outlet>
....
...
<footer></footer>
...
</div>
b。 LoginComponent或RegisterComponent(子組件)
<div>
Login view or Register view
...
</div>
c。添加路由器在app.routing.ts
{
path: '',
component: LandingComponent,
children: [
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent }
]
}
既有優點和缺點,這堅持是我的問題,
我個人很喜歡第二(II)的方法,任何擡頭會幫我到 做出決定。
這個答案需要澄清。我不知道「什麼時候配置路由結構」真的意味着或者與此有關。請澄清。 – 2017-03-24 02:21:17