Angular 2 Parent组件在子路由更改时再次调用/ Oninit

时间:2017-07-26 12:03:12

标签: angular angular2-routing angular-components angular-module

我正在使用默认加载的模块,如我们的应用路由模块配置:

     [
      { path: '', redirectTo: 'accounts', pathMatch: 'full' },
      { path: 'login', component: LoginComponent, pathMatch: 'full' },
      { path: 'accounts', loadChildren: './accounts/accounts.module#AccountsModule'},
      { path: 'report', component: PageNotFoundComponent, pathMatch: 'full' },
      { path: '**', component: PageNotFoundComponent }
];

以下是帐户模块的路由配置:

 [{ path: 'accounts', component: AccountsComponent, canActivate: [AuthGuardService], canActivateChild: [AuthGuardService], children: [
      { path: '', redirectTo: 'search', pathMatch: 'full' },
      { path: 'search', component: SearchComponent, pathMatch: 'full',data: { reuse: true } },
      {path: 'docDetails/:id', component: DocDetailComponent,children: [
              { path: '', redirectTo: 'overview', pathMatch: 'full' },
              { path: 'overview', component: OverviewComponent, pathMatch: 'full' },
              { path: 'update', component: UpdateComponent }
            ] }
      ] }
  ];

在我的帐户组件模板accounts.component.html中,我添加了一个默认加载的模块,并提供了如下所示的路由器插座:

<navbar><navbar>
<router-outlet></router-outlet>

问题是在每个子路由上再次调用更改帐户组件oninit函数,以及再次创建构造函数。

  

假设我从accounts/search移到/accounts/docDetails/12,帐户组件再次启动。我对延迟加载模块没有任何要求,我甚至可以使用急切加载,因此它们中的任何一个都适合我。只是根据角度文档,我无法找到任何其他方式来加载模块。

0 个答案:

没有答案