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

Ayd*_*kov 6 angular angular6

我有一个customer带有customer-routing模块的模块:

const routes: Routes = [
  {
    path: '', component: CustomerComponent,
    children: [
      { path: 'edit', component: EditCustomerComponent }
    ]
  }
];
Run Code Online (Sandbox Code Playgroud)

这是我的app-routing模块:

const routes: Routes = [
  { path: 'customers/:id', loadChildren: './customer/customer.module#CustomerModule' },
  { path: 'login', component: LoginComponent}
];
Run Code Online (Sandbox Code Playgroud)

但是当我遵循这样的路径时,customers/3/edit它告诉我总是CustomerComponent不会EditCustomerComponent

也许延迟加载不起作用?

PS:我使用的是 angular 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 { }
Run Code Online (Sandbox Code Playgroud)

小智 4

您不必将编辑路线放在孩子下。您的客户路由模块将如下所示:

const routes: Routes = [
  { path: '', component: CustomerComponent },
  { path: 'edit', component: EditCustomerComponent }
];
Run Code Online (Sandbox Code Playgroud)

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

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class CustomerRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

希望这能解决您的路由问题。