代码之家  ›  专栏  ›  技术社区  ›  JSON

如何将子组件设置为路由器出口的默认路由?[副本]

  •  1
  • JSON  · 技术社区  · 6 年前

    我正在使用 Lazyloading 我有两个 router-outlets . 当我想导航到另一个子路由时,就会出现问题。我得到这个错误,

    TypeError:无法读取未定义的属性“split” 默认URLMatcher(router.js:566) 在match(router.js:2221)。。。。。

    我的主应用程序路由器模块看起来像,

    const appRoutes: Routes = [
        { path: '', redirectTo: 'web/welcome' , pathMatch: 'full' },
        { path: 'web', redirectTo: 'web/welcome' , pathMatch: 'full' },
        {
            path: 'web',
            loadChildren: 'app/core/website/modules/website.module#WebSiteModule',
            data: { preload: true }
         },
        {
            path: 'dbapp', canActivate: [AuthGuardService],
            loadChildren: 'app/core/database/modules/db.module#DbModule',
            data: { preload: true }
         },
        { path: '**', redirectTo: '/404',  pathMatch: 'full'},
        { path: '**', component: NotFoundComponent, data: { message: 'We Could Not Serve Your Request!'}},
    ];
    

    对于 dbapp 我有这个路由模块,

    const dbRoutes: Routes = [
      {
        path: '',
        component: DbHomeComponent,
        data: { preload: true },
        pathMatch: 'full',
        children: [
          { path: '', component: UserDashboardComponent },
          {
            path: 'registry',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['reg'] } },
            loadChildren:
              'app/core/database/database-cores/registry-core/modules/registry.module#RegistryModule'
            // canActivateChild: [RoleGuardService]
          },
          {
            path: 'embryology',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['emb'] } },
            loadChildren:
              'app/core/database/database-cores/embryology-core/modules/embryology-routing.module#EmbryologyRoutingModule'
          },
          {
            path: 'nursing',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['nur'] } },
            loadChildren:
              'app/core/database/database-cores/embryology-core/modules/embryology-routing.module#EmbryologyRoutingModule'
          }
        ]
      },
    ]; 
    

    我的地图如下所示,

    enter image description here 路由器映射,带下划线 components 路由器出口

    所以根据我的配置。路由开始于 https://www.artngcore.com:4200/web/welcome 身份验证后,路由更改为 https://www.artngcore.com:4200/dbapp

    我设法导航到 UserDashboardComponent 作为默认路由,如果我向其他子级进行路由,我的问题是。 routerLink="/dbapp/registry"

    如何将子组件显示为默认管线并导航到其他子管线?

    1 回复  |  直到 6 年前
        1
  •  2
  •   JSON    6 年前

    已解决,答案来自 here ,

    所以我的 dbapp 路由模块应该是这样的,

    const dbRoutes: Routes = [
      {
        path: '',
        component: DbHomeComponent,
        data: { preload: true },
        children: [
          { path: '', component: UserDashboardComponent },
          {
            path: 'registry',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['reg'] } },
            loadChildren:
              'app/core/database/database-cores/registry-core/modules/registry.module#RegistryModule'
            // canActivateChild: [RoleGuardService]
          },
          {
            path: 'embryology',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['emb'] } },
            loadChildren:
              'app/core/database/database-cores/embryology-core/modules/embryology-routing.module#EmbryologyRoutingModule'
          },
          {
            path: 'nursing',
            canActivate: [RoleGuardService],
            data: { expectedRole: { roles: ['nur'] } },
            loadChildren:
              'app/core/database/database-cores/embryology-core/modules/embryology-routing.module#EmbryologyRoutingModule'
          }
        ]
      }
    ];
    

    我所要做的就是改变路由匹配策略, pathMatch: 'full' 不应包括在内