为什么在导航到另一个组件时又要重新加载当前组件?

时间:2018-10-19 12:25:15

标签: angular angular-routing angular-module

模块层次结构:

- App Module
  - Pages Module
    - Dashboard Module
    - Modules Module (Field Component)

应用模块导入AppRoutingModule AppRoutingModule:

const routes: Routes = [
  { path: 'pages', loadChildren: 'app/pages/pages.module#PagesModule' },
  { path: 'auth', loadChildren: 'app/auth/auth.module#AuthModule' },
  { path: '', redirectTo: 'pages', pathMatch: 'full' },
  { path: '**', redirectTo: 'pages' },
];

页面模块:

const PAGES_COMPONENTS = [
  PagesComponent,
];

@NgModule({
  imports: [
    PagesRoutingModule,
    DashboardModule,
    ModulesModule,
    UserModule,
  ],
  declarations: [
    ...PAGES_COMPONENTS,
  ],
  providers: [ModuleService],
})
export class PagesModule {
}

模块模块:

@NgModule({
  imports: [
    ThemeModule,
    ModulesRoutingModule,
  ],
  declarations: [
    ...routedComponents,
  ],
  providers: [
    ForecastService,
],
})
export class ModulesModule { }

问题: 我登录到页面。仪表板组件已加载,我导航到为数据调用服务(API)的字段组件。但是,当我导航至仪表板组件时,会再次调用该API。我在控制台网络和console.log中看到它。为什么导航到仪表板组件时会加载字段组件?

0 个答案:

没有答案