代码之家  ›  专栏  ›  技术社区  ›  Shady Aziza

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

  •  1
  • Shady Aziza  · 技术社区  · 6 年前

    我们有以下路由方案:

    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 用户ID

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

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

    2 回复  |  直到 6 年前
        1
  •  2
  •   Shady Aziza    6 年前

    基于来自的提示 Jota.Toledo ,解决方案是在我使用 Router.forRoot() 这样地:

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

    然后

    RouterModule.forRoot(routes,routingConfiguration),
    
        2
  •  0
  •   samar taj Shaikh    6 年前

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

    使用 this._route.parent.params this._route.params

    哪里 this._route private _route: ActivatedRoute

    推荐文章