没有参数值的路由;Angular 路由重定向 - 我可以使用 redirectTo 参数路径吗?

Сво*_*Роб 2 angular-routing angular2-routing angular

如果可以将 path: ' ' 重定向到 path: ':id' ,我正在徘徊?有没有办法实现这一目标?

谢谢你。

{
  path: 'folder',
  children: [
    {
      path: '',
      redirectTo: ':id',
      pathMatch: 'full',
    },
    {
      path: ':id',
      canActivate: [AuthGuard],
      component: DocumentsComponent,
    },
  ]
}
Run Code Online (Sandbox Code Playgroud)

Сво*_*Роб 7

我找到了一种使用空的“id”参数将“文件夹”路由重定向到“文件夹/:id”的方法:

{
    path: 'folder',
    redirectTo: 'folder/',
    pathMatch: 'full',
},
{
    path: 'folder',
    children: [
        {
            path: ':id',
            canActivate: [AuthGuard],
            component: DocumentsComponent,
        },
    ]
}
Run Code Online (Sandbox Code Playgroud)

*注意重定向必须是第一个。