Angular 2 Meteor的登录逻辑?

Angular 2 Meteor的登录逻辑?,angular,meteor,login,angular-meteor,angular2-meteor,Angular,Meteor,Login,Angular Meteor,Angular2 Meteor,我想实现一个典型的登录/注册设置: 如果用户未登录,则阻止他们访问/app和/app的所有子项 阻止用户在登录时访问/登录和/或注册 现在,我使用的设置如下所示: @Injectable() export class LoggedInGuard implements CanActivate, CanActivateChild { canActivate(...): boolean { if (Meteor.userId() != null) {

我想实现一个典型的登录/注册设置:

  • 如果用户未登录,则阻止他们访问/app和/app的所有子项
  • 阻止用户在登录时访问/登录和/或注册
现在,我使用的设置如下所示:

@Injectable()
export class LoggedInGuard implements CanActivate, CanActivateChild {
    canActivate(...): boolean {
        if (Meteor.userId() != null) {
            return true;
        }
        this.router.navigate(['/login']);
        return false;
    }
    canActivateChild(...): boolean {
        return this.canActivate(childRoute, state);
    }
}
我把我的路由放进去,我把
{path:'app',component:TasksListComponent,canActivate:[LoggedInGuard]}
。但是,这并不阻止用户在登录时访问登录/注册页面。我想知道是否有更好的方法来做到这一点,而不创建另一个单独的注射


**注意-我没有使用Iron Router,我使用的是@angular/Router

如果用户登录,您可以将用户重定向到其他组件。只要把这个放在ngOnInit()中就行了

 ngOnInit() {
 //*** checking if user is already login if login redirect to someother page based on your custom condition
        if (Meteor.userId()) {
            this._router.navigate(['otherpage']);
        }

    }