我正在尝试在 Angular.js 2(2.0.0-rc.4)(由 angular cli 创建)中编写一个路由器保护,等待 AngularFire(2.0.0-beta.2)检查登录状态并登录用户(匿名)如果用户在允许进入状态之前已经登录。
我的守卫代码是:
canActivate() {
/* This part is to detect auth changes and log user in anonymously */
this.auth
.subscribe(auth => {
if (!auth) {
this.auth.login();
}
});
/* This part is to listen to auth changes and IF there is an auth, resolves this guard with a true to let user in */
return this.auth
.asObservable()
.filter(auth => {
return auth ? true : false;
})
.map(x => {
console.log("TEST 1000");
return true;
});
}
当我运行该应用程序时,即使我看到TEST 1000
控制台输出表明canActivate()
返回true
我的路线未激活。
我想知道我的逻辑是否有错误的想法,或者有什么聪明的想法可以智能地调试它。