假设我们有4个模块:

  • AppRouting.module
  • Recipe.module
  • RecipeRouting.module
  • App.module

我们也在处理角制模块:RouterModule

AppRouting.module个英寸S NGMODULE看起来像这样:

 imports: [
        RouterModule.forRoot(appRoutes)
    ],

  exports: [RouterModule]

百寸S模块如下所示:

imports: [
    CommonModule,
    RouterModule.forChild(routes)
  ],
  exports: [
    RouterModule
  ]

Recipe.module个‘S NGMODULE如下所示

exports: [
    // bunch of components and directives
  ],
imports: [
    RecipeRoutingModule
  ]

最后App.module个看起来是这样的

// we import a bunch of necessary modules
 imports: [
 AppRouteModule,
 RecipesModule
  ],
// why is it that we don't have to import the `RecipeRouting.module`? 

正如最后一个片段中的问题所述,为什么我们不在App模块中导入RecipeRouting.module个呢?我有一种感觉,它一定与RouterModule有关,因为这是我们在该模块中唯一要导出的东西,我们已经导入了RouterModule,并且我们已经使用forChild对类进行了更改?

任何解释都是很棒的!

推荐答案

Its because when you import the router module of another module, it overrides the default routing configured in 100

Routes of RouterModule.forRoot(appRoutes)->;Get被RecipeRouting.module Routes覆盖

RecipeRouting.module不是RecipeModule的导入,我们需要将RecipeModule加载为惰性/渴望加载模块!

Angular相关问答推荐

Angular:浏览器中未显示一些Google Content图标

Angular 服务错误处理响应类型=BLOB

如果Angular 模块是独立的,为什么我不需要在App模块中使用RouterModule?

更改动态表单控制Angular 的值

RXJS拆分返回值,多次调用后重新加入

从 applescript 调用Angular 前端以从列表中 Select 一个项目

区分material 手风琴

大型 Angular 12 应用程序 - 我如何管理 js 文件

根据最后发出的 observable 创建一个 observable

手动关闭 SSE 连接:Angular

如何处理Angular 延迟订阅

as和let之间的异步管道区别

Angular 没有可用于依赖类型的模块工厂:ContextElementDependency

如何使用 Bootstrap 4 flexbox 填充可用内容?

Angular url加号转换为空格

相对于根目录的 SCSS 导入

设置 Angular Material Tooltip 的字体大小

Angular 4中的md-select中的onselected事件

Firestore 从集合中获取文档 ID

包 '@angular/cli' 不是依赖项