本文介绍了Angular 6-延迟加载模块的子路径未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在延迟加载的模块中使用路由,但是它不起作用.
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
}
];
这是用于延迟加载模块的RoutingModule.
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 }
]
},
];
我可以导航到 http://localhost:4200 和 http://localhost:4200/holiday 正确.
但是当我尝试时, http://localhost:4200/holiday/1 它将在控制台中抛出404.
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)
这些是package.json中的依赖项,以备不时之需.
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",
推荐答案
请查看此示例
https://angular-svs3xe.stackblitz.io
https://stackblitz.com/edit/angular-svs3xe
这篇关于Angular 6-延迟加载模块的子路径未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!