我正在使用默认加载的模块,如我们的应用路由模块配置:
[
{ 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
,帐户组件再次启动。我对延迟加载模块没有任何要求,我甚至可以使用急切加载,因此它们中的任何一个都适合我。只是根据角度文档,我无法找到任何其他方式来加载模块。