像 Angular UI Router 一样,Angular2 中是否可以有多个具有相同 URL 的路由?例如以下两条路线:
{ path: '/home', name: 'Home', component: HomeComponent} ,
{ path: '/home', name: 'Dashboard', component: DashboardComponent}
目前,控制台中出现路由冲突的错误。
像 Angular UI Router 一样,Angular2 中是否可以有多个具有相同 URL 的路由?例如以下两条路线:
{ path: '/home', name: 'Home', component: HomeComponent} ,
{ path: '/home', name: 'Dashboard', component: DashboardComponent}
目前,控制台中出现路由冲突的错误。
AuxRoute
如果您想要ui-router
命名样式,您可以使用ui-view
.
https://angular.io/docs/ts/latest/api/router/AuxRoute-class.html
另外,参考这个问题。 Angular 2 辅助路由器坏了吗?
您可以检查Angular2 - 两个具有相同路线的组件,讨论可能的解决方案以实现您所追求的目标。
在模板中使用 *ngIf 以根据评估条件使用不同的选择器。
<home-logged-in *ngIf="authenticated()"></home-logged-in>
<home-logged-out *ngIf="!authenticated()"></home-logged-out>
创建将根据评估条件加载特定组件的自定义路由器插座。
根据评估条件重定向到不同的路线(参见来源http://www.captaincodeman.com/2016/03/31/angular2-route-security/)
此列表不是决定性的,可能还有其他方法可以实现您的目标。