0

当我尝试登录我的应用程序时出现此错误,但我遇到了一些包含 404(未找到)的问题...我将输入我的一些代码行和错误图像.....请帮助我解决问题。

@Injectable()
export class AuthGuard implements CanActivateChild {
  loggedInUser: string;

  constructor( private localStorage: LocalStorageService, private router: Router ) {
    this.loggedInUser = localStorage.get('discogs-user') as string;
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    if (this.loggedInUser) {
      return true;
    }

    this.router.navigate(['/login']);
  }
}

这是带有订阅的 login.component.ts

import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';

import { Observable } from 'rxjs/Observable';

import { MdlSnackbarService } from 'angular2-mdl';

import * as fromRoot from '../../reducers';
import * as user from '../../actions/user';

import { DiscogsUser, UserLogin } from '../../models';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html'
})
export class LoginComponent {
  user$: Observable<DiscogsUser>;

  login(login: UserLogin) {
    if (!login.username) {
      this.store.dispatch(new user.LoginFailedAction('You must enter a username'));
      return;
    }

    this.store.dispatch(new user.LoginAction(login));
    this.router.navigate(['/']);
  }

  private _showError(message: string) {
    this.mdlSnackbarService.showSnackbar({
      message: message,
      action: {
        handler: () => { },
        text: 'OK'
      }
    });
  }

  constructor(private store: Store<fromRoot.State>, private router: Router, private mdlSnackbarService: MdlSnackbarService) {
      this.user$ = store.select(fromRoot.getUser);

      store.select(fromRoot.getLoginFailed)
        .subscribe(error => {
          if (error) {
            this._showError(error);
          }
        });

    }
}

这是错误的图像

错误

4

0 回答 0