我有一个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 { }
答案 0 :(得分:1)
您不必将编辑路线放在孩子下方。您的客户路由模块将如下所示:
const routes: Routes = [
{ path: '', component: CustomerComponent },
{ path: 'edit', component: EditCustomerComponent }
];
还要确保检查客户路由模块中是否使用forChild函数导入了该路由数组,如下所示:
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class CustomerRoutingModule { }
希望这可以解决您的路由问题。