我已经在调用 AngularFireAuth 的 authState 方法的路由之一中实现了一个 Auth 保护。
我已经看到很多像下面这样授予访问权限的示例:
return this.afAuth.authState.map(user => {
if(isNullOrUndefined(user)){
this.router.navigate(['auth/login']);
return false;
}else{
return true;
}
})
但是当我尝试按原样复制它时,我收到以下错误:'...Property 'map' doesn't exist on type 'Observable'。
但是当我包含 .pipe 时,它按预期工作:
return this.afAuth.authState.pipe(map((user) => {
if(isNullOrUndefined(user)){
this.router.navigate(['auth/login']);
return false;
}else{
return true;
}
} ))
也许我应该对它的工作方式感到满意,但我不明白为什么这里需要管道。任何人都会有几分钟的时间向我解释这一点?
非常感谢 !纳内克斯