路由器商店无法识别路由器参数 [英] Router store does not recognize router params

查看:53
本文介绍了路由器商店无法识别路由器参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下路由方案:

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,但是当我们删除 children 属性时,它确实识别了 userId 的值.

Our router store does not recognize userId this way but when we remove the children property it does recognize the value of userId.

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

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

What is the reason behind this behavior?

推荐答案

基于 Jota.Toledo ,解决方案是定义一个路由配置,我使用 Router.forRoot() 像这样:

Based on the hint from Jota.Toledo ,The solution was to define a routing configuration where I use Router.forRoot() like this:

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

然后

RouterModule.forRoot(routes,routingConfiguration),

这篇关于路由器商店无法识别路由器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆