简体   繁体   English

Angular 6-延迟加载模块的子路径未加载

[英]Angular 6 - Children paths of lazy loaded module are not loading

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. 这是用于延迟加载模块的RoutingModule。

   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. 我可以正确导航到http:// localhost:4200http:// localhost:4200 / holiday

But when I try http://localhost:4200/holiday/1 it throws 404 in console. 但是当我尝试 http:// localhost:4200 / holiday / 1时,它将在控制台中抛出404。

GET http://localhost:4200/holiday/runtime.js net::ERR_ABORTED 404 (Not Found)

These are dependencies in package.json in case you need it. 如果需要,这些是package.json中的依赖项。

"@angular/cli": "^6.2.6",
"@angular/router": "^6.1.10",
"@angular/core": "^6.1.10",

Please look at this example 请看这个例子

   https://angular-svs3xe.stackblitz.io

   https://stackblitz.com/edit/angular-svs3xe

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 }
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM