Created
February 10, 2020 12:08
-
-
Save abhishekluv/2b8760d4b0d08bb51a73305a6b51c455 to your computer and use it in GitHub Desktop.
Angular Source Code Demo 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; | |
import { Observable } from 'rxjs'; | |
import { CanActivate } from '@angular/router'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthGuard implements CanActivate { | |
constructor(private router: Router) { | |
} | |
canActivate(next: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot): boolean { | |
if (localStorage.getItem('token') != null) { | |
return true; | |
} else { | |
this.router.navigateByUrl('/login'); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment