我创建了一个产品文件夹,其中包含products-home.component(parent)和products-list.component(child)并命名为 outlet。
Error: Cannot match any routes. URL Segment: 'products'
当导航到products-list
使用延迟加载时,我得到了。
这在急切加载时有效
app.module.ts
@NgModule({
imports: [ ...,ProductsModule ]
})
产品.module.ts
@NgModule({
imports: [
RouterModule.forRoot([
{
path: "products",
component: ProductsHomeComponent,
children: [
{
path: "products-list",
component: ProductsComponent,
outlet: "content"
}
]
}
])
]
})
这在延迟加载时不起作用
app.module.ts
const LazyRoutes: Routes = [
{
path: 'products',
loadChildren: './products/products.module#ProductsModule'
}
];
@NgModule({
imports: [ RouterModule.forRoot(LazyRoutes) ]
})
产品.module.ts
@NgModule({
imports: [
RouterModule.forChild([
{
path: "",
component: ProductsHomeComponent,
children: [
{
path: "products-list",
component: ProductsComponent,
outlet: "content"
}
]
}
])
]
})