【发布时间】:2019-01-08 18:26:01
【问题描述】:
我正在尝试在 Angular 6 中实现路由,但 NgModules 的多个级别存在问题。
模块的结构如下(B和C是A的孩子):
A_Module
B_Module
C_Module
这是我的顶级 NgModule 中的一段代码:
// A_Module
const routes = [
{ path: 'B', component: B_Component },
{ path: 'C', component: C_Component },
]
@NgModule({
declarations: [
A_Component
],
imports: [
B_Module,
C_Module,
RouterModule.forRoot(routes),
],
providers: [],
bootstrap: [A_Component]
})
export class A_Module { }
B_Component 和 C_Component 是其自身模块中的顶级组件。
此解决方案不起作用,因为在此 A_Module 中没有声明来自 B_Module 或 C_Module 的组件。问题是在 B_Module 和 C_Module 内部有许多组件,将所有内容移至 A_Module 并不是解决方案(这就是为什么要正确制作模块 - 清理和分离代码?)。
有什么解决办法吗?
【问题讨论】:
标签: angular module routing components