openaire-library/error/isDevelopmentGuard.guard.ts

27 lines
908 B
TypeScript
Raw Normal View History

2022-10-10 15:56:13 +02:00
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot, UrlSegment, UrlTree} from '@angular/router';
import {Observable} from 'rxjs';
import {properties} from "../../../environments/environment";
@Injectable()
export class isDevelopmentGuard implements CanActivate, CanLoad {
constructor(private router: Router) {
}
check(): Observable<boolean> | boolean {
if(properties.environment == 'development') {
return true;
} else {
this.router.navigate([properties.errorLink]);
}
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree{
return this.check();
}
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.check()
}
}