Tejashri Patange
Tejashri Patange

Reputation: 339

Cannot read property 'loadChildren' of undefined

Following is my router page:

export const AppRoutes: Routes = [
{
   path: '',
   component: PublicComponent,
   children: [
   {
    path: '',redirectTo: '/',pathMatch: 'full'
   },
   {
    path: 'home',loadChildren: () => HomeModule
   }
 ]
} ,
{
  path: '',component: AdminComponent, children: [
  {
    path: 'dashboard', loadChildren: () => DashboardModule
  }, {...}
 ]
},
{ path: '**', redirectTo: '/home', pathMatch: 'full' }
];

@NgModule({
imports: [
 RouterModule.forRoot(AppRoutes, {scrollPositionRestoration: 'enabled'})
],
exports: [RouterModule]
})

When I run the project for the first time, it gives me the above error.

Note:I'm implementing lazy loading approach.

Upvotes: 0

Views: 1719

Answers (2)

Rafał Olbracht
Rafał Olbracht

Reputation: 1

I had this issue. Check if you use aot, e.g. ng serve --open --aot or turn it on in package.json

Upvotes: 0

Matt U
Matt U

Reputation: 5118

I'm not really familiar with the syntax you've used for loadChildren. Try this instead:

loadChildren: './path/to/your.module#YourModule

This GitHub issue suggests that fix. It looks like the issue here may be similar: https://github.com/angular/angular/issues/31206

Upvotes: 1

Related Questions