具有多个组件的延迟加载功能模块在角度6中不起作用

我有一个带客户路由模块的客户模块:

const routes: Routes = [
  {
    path: '', component: CustomerComponent,
    children: [
      { path: 'edit', component: EditCustomerComponent }
    ]
  }
];

这是我的app-routing模块:

const routes: Routes = [
  { path: 'customers/:id', loadChildren: './customer/customer.module#CustomerModule' },
  { path: 'login', component: LoginComponent}
];

但是,当我按照这样的路径进行客户/ 3 /编辑时,它始终显示CustomerComponent而不是EditCustomerComponent.

也许懒加载不起作用?

PS:我使用角度6.1.0

更新:我的客户模块

import {ReactiveFormsModule} from '@angular/forms';
import {CustomerComponent} from './customer.component';
import {EditCustomerComponent} from './edit-customer.component';

@NgModule({
  imports: [
    CommonModule,
    CustomerRoutingModule,
    ReactiveFormsModule
  ],
  declarations: [CustomerComponent, EditCustomerComponent]
})
export class CustomerModule { }

最佳答案 您不必在子项下放置编辑路径.您的客户路由模块将如下所示:

const routes: Routes = [
  { path: '', component: CustomerComponent },
  { path: 'edit', component: EditCustomerComponent }
];

还要确保在客户路由模块中使用forChild函数检查是否已导入此路由数组,如下所示:

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class CustomerRoutingModule { }

希望这可以解决您的路由问题.

点赞