0
非同期http要求で戻り値に問題があります。角2のガード - 非同期のユーザーの要求
登録を待つ方法
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
) {
if (this.auth.currentUser) {
return true;
} else {
this.auth.getUser()
.subscribe(resp => {
if (this.auth.currentUser) {
return true;
} else {
this.router.navigate(['login'], {
queryParams: {
returnUrl: state.url
}
});
return false;
}
})
}
}
ページを更新してメインページにリダイレクトしても結果は返されません。
恐らくhttps://stackoverflow.com/questions/38425461/angular2-canactivate-calling-async-functionとhttps://stackoverflow.com/questions/41377014/angular-2-canactivate-asyncの複製 –