我正在尝试注销然后导航到登录URL,但是来自此URL的authguard会阻止已登录的用户查看它,并且因为在解析承诺之前已到达第二行,您需要单击方法事件两次以使其工作.
logout(){ this.angularfire.auth.logout(); this.router.navigate(['']); }
当promise被解决时,有没有办法在回调中实现router.navigate?我已经尝试过then(),但是我的语法不正确或者auth typings有问题……
解决方法
AngularFire2的注销应该以与底层Firebase SDK类似的方式运行.幸运的是,几天前,a PR was merged更改了注销以返回一个承诺 – 所以下一个版本将解决您的问题.
在此之前,您可以收听身份验证更改以确定何时可以导航:
import "rxjs/add/operator/filter"; import "rxjs/add/operator/first"; ... logout(){ this.angularfire.auth // You only want unathenticated states: .filter((authState) => !authState) // You only want the first unathenticated state: .first() // You should now be able to navigate: .subscribe(() => this.router.navigate([''])); // The composed observable completes,so there's no need to unsubscribe. this.angularfire.auth.logout(); }