问题
I am trying to work with routing in lazy loaded modules, but it is not working.
This is my app module routing.
export const routes: Routes = [
{
path: '',
component: DefaultLayoutComponent,
data: {
title: 'Home'
},
children: [
{
path: 'holiday',
loadChildren: './holiday/holiday.module#HolidayModule'
}
]
},
{
path:"**",
component:P404Component
}
];
This is RoutingModule for lazy-loaded module.
const routes: Routes = [
{
path: '', children: [
{ path: '', component: HolidayBookingComponent },
{ path: ':id', component: HolidayBookingComponent },
{ path: 'booking', component: HolidayBookingComponent },
{ path: 'review', component: HolidayReviewComponent }
]
},
];
I can navigate to http://localhost:4200 and http://localhost:4200/holiday correctly.
But when I try http://localhost:4200/holiday/1 it throws 404 in console.
GET http://localhost:4200/holiday/runtime.js net::ERR_ABORTED 404 (Not Found)
These are dependencies in package.json in case you need it.
"@angular/cli": "^6.2.6",
"@angular/router": "^6.1.10",
"@angular/core": "^6.1.10",
回答1:
Please look at this example
https://angular-svs3xe.stackblitz.io
https://stackblitz.com/edit/angular-svs3xe
回答2:
You probably want this for your lazy routes:
const routes: Routes = [
{ path: '', component: HolidayBookingComponent },
{ path: ':id', component: HolidayBookingComponent },
{ path: 'booking', component: HolidayBookingComponent },
{ path: 'review', component: HolidayReviewComponent }
];
来源:https://stackoverflow.com/questions/53389882/angular-6-children-paths-of-lazy-loaded-module-are-not-loading