Angular2路由匹配特定值
问题描述:
我想找到一种方式来显示特定的组件时,只有一个特定的值。 基本上这是现在是如何寻找路由:Angular2路由匹配特定值
const routes: Routes = [
{
path: 'users',
component: MainComponent,
children: [
{
path: ':id',
component: DashboardComponent,
children: [
{
path: '1',
component: NeedToRenderThisComponent
},
{
path: '',
component: DashboardComponent
},
{
path: '',
outlet: 'sidebar',
component: SidebarComponent
}
]
}
]
}
];
所以,我在找的是用户点击时,或在进入“/用户/ 1”,用户将看到NeedToRenderThisComponent另一种方式。对于所有其他值,将会有DashboardComponent。
DashboardComponent包含两个路由器网点
<router-outlet name="sidebar"></router-outlet>
<router-outlet></router-outlet>
答
您可以使用一个path: '**'
路线,然后添加在Angular 2 dynamic tabs with user-click chosen components自己喜欢显示的组件。
AFAIK没有办法匹配值。在较旧的路由器中存在正则表达式路由,但在当前的路由器中,尚未实现(尚未?)。
更新
自定义路径的匹配支持纷纷落地并很可能会提供下一个更新 https://github.com/angular/angular/issues/12442
所以基本上thiss会匹配一切,并会呈现组件,然后在部分我会根据url来动态显示组件,对不对? – user2732627
没错,那是我的想法。 –
似乎支持自定义路径匹配已着陆。看到我更新的答案。 –