Angular2 - 具有相同路线的两个组件

Angular2 - two components with the same route

在 angularJS ui-router 中,我们可以使用状态相同的路由使用 2 个组件(如本例 Angular UI Router: Different states with same URL?)。

是否可以在 angular2 中实现相同的行为?如果可以,您可以 link/provide 一些示例或解决方法吗?

这里的用例类似于 Facebook 或 Twitter,其中 URL 保持不变,但内容会根据您是否登录而变化。

到目前为止,我能想到的唯一方法是在 'parent' 模板中使用 *ngIf 到 select select 或者两个 'children' 组件。像这样:

<home-logged-in *ngIf="authenticated()"></home-logged-in>
<home-logged-out *ngIf="!authenticated()"></home-logged-out>

有推荐的方法吗?

谢谢

你可以有参数像

的路由

/article/:id/detail

其中 /article/123/detail/article/abc/detail 指向相同的组件。

参见本教程的示例 https://angular.io/docs/ts/latest/tutorial/toh-pt5.html(搜索 "Configure a Route with a Parameter")