Issue
We get an error cannot find module
in case following structure.
app-routing.module.ts
const routes: Routes = [
{
path: CHILD_MANAGEMENT_PORTAL.baseUrl,
canActivate: [AuthGuard],
component: EnvelopeComponent,
loadChildren: () =>
import('./features/child-management/child-management.module').then(
m => m.ChildManagementModule
),
data: {
menuResolver: ChildManagementMenuResolver,
pageTitleResolver: ChildManagementPageTitleResolver,
portalData: CHILD_MANAGEMENT_PORTAL
}
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
child-management-routing.module.ts : wrong
const routes: Routes = [
{
path: 'dashboard',
loadChildren: './dashboard/child-dashboard.module#ChildDashboardModule'
},
{
path: '**',
redirectTo: 'dashboard'
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: []
})
export class SalesArrangementManagementRoutingModule {}
We could solve this error by only changing loadChildren of child routing.module from loadChildren: './hoge.module#HogeModule'
to loadChildren: () => import('./hoge.module.ts).then(m => m.HogeModule)'
.
child-management-routing.module.ts : correct
const routes: Routes = [
{
path: 'dashboard',
loadChildren: () => import('./dashboard/child-dashboard.module').then(m => m.ChildDashboardModule)
},
{
path: '**',
redirectTo: 'dashboard'
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: []
})
export class SalesArrangementManagementRoutingModule {}
But I could not understand why. (I did not change app-routing.module.ts...)
So could you explain the difference?
It seems like you upgraded from Angular 7.x to 8.x and this is where the scheme changed.
Explanation (From angular docs)
Hope this helps you out.