I want use lazy loading in your app. A have 2 modules: login and cars. Lazy loading is working fine, but route /add-car not working. Why? Path /add-car is not found and redirect to PageNotFoundComponent.
app.routing.module.ts
const appRoutes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'login'
},
{
path: 'cars',
canLoad: [AuthCanLoadGuard],
loadChildren: './cars/cars.module#CarsModule',
},
{
path: 'user-account',
component: UserAccountComponent,
canActivate: [AuthGuardsService]
},
{
path: '**',
component: PageNotFoundComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes, {enableTracing: true})],
exports: [RouterModule]
})
cars.routing.module.ts
const carsRoutes: Routes = [
{
path: '',
component: CarsComponent,
children: [
{
path: '',
component: CarsListComponent,
resolve: { cars : CarsListResolve } // przeniesione z app.routing.module.ts
},
{
path: ':id',
component: CarsDetailsComponent,
canDeactivate: [FormCanDeactivateGuard],
resolve: { car: CarResolve }
}
]
},
{
path: '/add-car',
component: AddCarComponent,
}
];
@NgModule({
imports: [RouterModule.forChild(carsRoutes)],
exports: [RouterModule]
})