Angular 路由器存储区无法识别路由器参数

Angular 路由器存储区无法识别路由器参数,angular,angular6,ngrx,ngrx-store,ngrx-router-store,Angular,Angular6,Ngrx,Ngrx Store,Ngrx Router Store,我们有以下路由方案: export const ROUTES: Routes = [ { path: ':userId', component: fromContainers.OrganizationComponent, canActivate: [], children: [ { path: '', pathMatch: 'full', redirectTo: 'posts' }, { path: 'posts',

我们有以下路由方案:

export const ROUTES: Routes = [
  {
    path: ':userId',
    component: fromContainers.OrganizationComponent,
    canActivate: [],
    children: [
      { path: '', pathMatch: 'full', redirectTo: 'posts' },
      {
        path: 'posts',
        loadChildren: './views/posts/posts.module#PostsModule'
      }
    ]
  }
];
我们的路由器存储区不会以这种方式识别
userId
,但是当我们删除
子属性时,它会识别
userId
的值

http://localhost:4200/user/r1RORssFG --> WORKS
http://localhost:4200/user/r1RORssFG/posts --> DOES NOT WORK

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

我认为您无法从子路由访问父路由的参数

要从子组件访问父参数,请执行以下操作:

使用
this.\u route.parent.params
代替
this.\u route.params

其中
this.\u route
private\u route:ActivatedRoute
根据中的提示,解决方案是定义一个路由配置,我在其中使用
Router.forRoot()
,如下所示:

export const routingConfiguration: ExtraOptions = {
  paramsInheritanceStrategy: 'always'
};
然后

RouterModule.forRoot(routes,routingConfiguration),

控制台上是否有错误?完全没有错误,我们可以在检查Redux devtool时验证是否未读取
用户ID
,您所说的
无法识别是什么意思?serialited paramsMap值不包含
用户ID
http://localhost:4200/user/r1RORssFG
在此路由中,
用户ID
参数具有正确的值
http://localhost:4200/user/r1RORssFG/posts
在本例中
userId
param没有值@Jota.toledo您配置了什么Router.forRoot方法中的
paramsInheritance
?这是一种正确但不好的方法,因为它并不真正对重构友好。对路线定义所做的更改将打破这一点。好吧,我不这么认为,当你知道路线不会改变时,这是一种方便的方法。