CanActivate在firebase的Angular 7中表现不正常

CanActivate在firebase的Angular 7中表现不正常,angular,typescript,firebase-authentication,angularfire2,angular7,Angular,Typescript,Firebase Authentication,Angularfire2,Angular7,在我的Authservice中,我有: getAuthenticationState(): Observable<any> { return this.angularFireAuth.authState; } 我的问题是,我必须单击登录按钮两次(我确信它是按照它应该的方式实现的),似乎防护装置不是作为可观察的对象工作的,loggedIn值只打印一次。添加take(1)来解决它,以及为什么要使用2个管道,将其更改为 return this.authService.g

在我的
Authservice
中,我有:

  getAuthenticationState(): Observable<any> {
    return this.angularFireAuth.authState;
  }
我的问题是,我必须单击登录按钮两次(我确信它是按照它应该的方式实现的),似乎防护装置不是作为可观察的对象工作的,loggedIn值只打印一次。

添加take(1)来解决它,以及为什么要使用2个管道,将其更改为

 return this.authService.getAuthenticationState()
    .take(1)
    .pipe(
         map(user => !!user),
         tap(loggedIn => {
            console.log(loggedIn);
           if (!loggedIn) {
              this.router.navigate(['/admin/login']);
           } else {
              return true;
           }
         })
      );
 return this.authService.getAuthenticationState()
    .take(1)
    .pipe(
         map(user => !!user),
         tap(loggedIn => {
            console.log(loggedIn);
           if (!loggedIn) {
              this.router.navigate(['/admin/login']);
           } else {
              return true;
           }
         })
      );