简体   繁体   中英

Reusable component not seen by children routes components

I have 2 lazy loaded routes:

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.

I've added the component on Dashboard module and tried on AppModule too, but I get the same result. Am I missing something?

It's a common problem with the lazy loading routes in Angular, I believe. Although it is convenient to specify LoadChildren programmatically as you did, you have to use string instead, a la

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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