Add guard

This commit is contained in:
Peter Maquiran
2021-07-01 15:38:22 +01:00
parent 60906fff68
commit bb3c408595
2 changed files with 41 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(
private router:Router
){}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if(window.location.pathname != '' && !localStorage.getItem('UserData')) {
this.router.navigate(['/']);
return false
} else {
return true
}
}
}