路由器商店无法识别路由器参数

azi*_*iza 2 ngrx angular ngrx-store angular6 ngrx-router-store

我们有以下路由场景:

export const ROUTES: Routes = [
  {
    path: ':userId',
    component: fromContainers.OrganizationComponent,
    canActivate: [],
    children: [
      { path: '', pathMatch: 'full', redirectTo: 'posts' },
      {
        path: 'posts',
        loadChildren: './views/posts/posts.module#PostsModule'
      }
    ]
  }
];
Run Code Online (Sandbox Code Playgroud)

我们的路由器存储无法识别userId这种方式,但是当我们删除该children属性时,它确实识别了 的值userId

http://localhost:4200/user/r1RORssFG --> WORKS
http://localhost:4200/user/r1RORssFG/posts --> DOES NOT WORK
Run Code Online (Sandbox Code Playgroud)

这种行为背后的原因是什么?

azi*_*iza 6

基于来自Jota.Toledo的提示,解决方案是定义一个路由配置,我使用Router.forRoot()如下:

export const routingConfiguration: ExtraOptions = {
  paramsInheritanceStrategy: 'always'
};
Run Code Online (Sandbox Code Playgroud)

进而

RouterModule.forRoot(routes,routingConfiguration),
Run Code Online (Sandbox Code Playgroud)