File

src/app/guards/auth.guard.ts

Index

Methods

Constructor

constructor(router: Router, authService: AuthService)
Parameters :
Name Type Optional
router Router no
authService AuthService no

Methods

canActivate
canActivate()
Returns : boolean
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { AuthService } from '../services/auth.service';

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private router: Router, private authService: AuthService) {}

  canActivate() {
    if (this.authService.authenticated) {
      return true;
    }
    this.router.navigate(['/login']);
    return false;
  }
}

results matching ""

    No results matching ""