我想要建立一个角应用程序,其中有一个正常的注册/登录形式和一些不同的alt页面。
我的问题是我不知道如何控制不同的观点。例如,如果您使用普通用户类型登录,您可以看到视图1。
如果您使用其他用户类型登录,则会看到与其他用户类型不同的视图。
发布于 2017-09-05 07:32:28
您可以重定向到这样的卫队中的特定视图:
使用CanActivateChild保护路由文件中的children: []组件,否则使用接口CanActivate。应用的逻辑保持不变。
import {Injectable} from '@angular/core';
import {Router, CanActivateChild} from '@angular/router';
import {AuthenticationService} from '../services';
@Injectable()
export class LoginAuthGuard implements CanActivateChild {
  constructor(private router: Router,
              private authenticationService: AuthenticationService) {
  }
  canActivateChild(): boolean {
    if (this.authenticationService.isLoggedIn()) {
      if (**normal user type **) {
         this.router.navigate(['/view1']);
      } else {
         this.router.navigate(['/view2']);
      }
      return true;
    } else {
      this.router.navigate(['/login']);
      return false;
    }
  }
}https://stackoverflow.com/questions/46048952
复制相似问题