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

时间:2018-09-23 10:48:10

标签: angular angular6

我有一个customer模块和customer-routing模块:

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

但是当我遵循这样的路径customers/3/edit时,它总是显示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 { }

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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