0
は私がサブモジュールのリストを取得ngOnInit主成分でルーティング構造親ルートが
path: '',
component: MainComponent,
children: [
{path: 'employees', component: EmployeesComponent, canActivate: [AuthGuard], children: [
{path: '', component: EmployeeListComponent, pathMatch: 'full', canActivate: [AuthGuard]},
{path: ':id', component: EmployeeMainComponent, pathMatch: 'full', canActivate: [AuthGuard]}
]}
]
}
を持ってレンダリングした後にのみ、子ルートをレンダリング
getSubmodules(id) {
this.universityAsideService.getSubmodules(id)
.subscribe((subModules) => {
this.subModules = subModules;
this.saveSubModules(subModules).subscribe((data) => this.goToModule(id));
console.log('submodules in getSubmodules, UniversityAside Co');
console.log(this.subModules);
});
}
saveSubModules(subModules): Observable<any> {
return Observable.create((obs) => {
obs.next(localStorage.setItem('subModules', JSON.stringify({
subModules: subModules
})));
});
}
その後EmloyeesコンポーネントはのlocalStorageからサブモジュールのリストを取得し、ビューをレンダリング。 Bu訪問時の問題localhost:4200/#/employees/
従業員コンポーネントは、MainComponentをlocalstorageに保存する前にlocalstorageからサブモジュールを取得しようとします。どうすればこの問題を解決できますか?ありがとう。
:
のようなルートを修正しますか?何も思いつきません。 AuthGuardでは、ユーザーが署名されているかどうかだけをチェックします。 –
あなたのMainComponentがlocalstorageに保存されているかどうかをチェックしてください。 –
と同じように実装できます。 –