简体   繁体   English

子路由组件看不到的可重用组件

[英]Reusable component not seen by children routes components

I have 2 lazy loaded routes:我有 2 条懒加载路线:

const routes: Routes = [
{
    path: '',
    redirectTo: 'login',
    pathMatch: 'full'
  },
  {
    path: 'login',
    loadChildren: () => import('./login/login.module').then(m => m.LoginModule)
  },
  {
    path: 'dashboard',
    loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
  }
];

And dashboard route has children routes.仪表板路线有子路线。

const routes: Routes = [
  {
    path: '',
    component: DashboardComponent,
    children: [
      {
        path: '',
        component: HomeComponent
      },
      {
        path: 'usuarios',
        component: UsersComponent
      }
    ]
  }
]

I have created a toolbar reusable component, which I wanna render on dashboard router-outlet, but when I navigate to the children routes of dashboard module, angular compiler says that the app-toolbar is not a component.我创建了一个工具栏可重用组件,我想在仪表板路由器插座上呈现它,但是当我导航到仪表板模块的子路由时,angular 编译器说 app-toolbar 不是一个组件。

I've added the component on Dashboard module and tried on AppModule too, but I get the same result.我已经在 Dashboard 模块上添加了该组件并在 AppModule 上进行了尝试,但我得到了相同的结果。 Am I missing something?我错过了什么吗?

It's a common problem with the lazy loading routes in Angular, I believe.我相信这是 Angular 中延迟加载路由的常见问题。 Although it is convenient to specify LoadChildren programmatically as you did, you have to use string instead, a la虽然像您那样以编程方式指定LoadChildren很方便,但您必须使用 string 代替

loadChildren: './login/login.module#LoginModule',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM