我正在尝试在延迟加载的模块中使用路由,但是它不起作用。
这是我的应用模块路由。
export const routes: Routes = [
{
path: '',
component: DefaultLayoutComponent,
data: {
title: 'Home'
},
children: [
{
path: 'holiday',
loadChildren: './holiday/holiday.module#HolidayModule'
}
]
},
{
path:"**",
component:P404Component
}
];
这是用于延迟加载模块的RoutingModule。
const routes: Routes = [
{
path: '', children: [
{ path: '', component: HolidayBookingComponent },
{ path: ':id', component: HolidayBookingComponent },
{ path: 'booking', component: HolidayBookingComponent },
{ path: 'review', component: HolidayReviewComponent }
]
},
];
我可以正确导航到http://localhost:4200和http://localhost:4200/holiday。
但是当我尝试 http://localhost:4200/holiday/1时,它将在控制台中抛出404。
GET http://localhost:4200/holiday/runtime.js net::ERR_ABORTED 404 (Not Found)
这些是package.json中的依赖项,以备需要时使用。
"@angular/cli": "^6.2.6",
"@angular/router": "^6.1.10",
"@angular/core": "^6.1.10",
答案 0 :(得分:1)
请看这个例子
SortOrder
答案 1 :(得分:0)
您可能希望将其用于您的懒惰路线:
const routes: Routes = [
{ path: '', component: HolidayBookingComponent },
{ path: ':id', component: HolidayBookingComponent },
{ path: 'booking', component: HolidayBookingComponent },
{ path: 'review', component: HolidayReviewComponent }
];