如何将子组件设置为路由器插座的默认路由? [重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

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

TypeError:无法读取defaultUrlMatcher(router.js:566)匹配时未定义的属性'split'(router.js:2221).....

我的主app-router模块看起来像,

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路由器地图,加下划线的componentsrouter-outlets

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

我设法导航到UserDashboardComponent作为默认路线,我的问题,如果我做路由到其他孩子,即routerLink="/dbapp/registry"

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

angular lazy-loading angular-routing
1个回答
1
投票

解决了,答案来自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'

© www.soinside.com 2019 - 2024. All rights reserved.