openaire-library/connect/communityGuard/isCommunity.guard.ts

37 lines
932 B
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
import {
ActivatedRoute,
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
CanLoad, Route
} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/filter';
@Injectable()
export class IsCommunity implements CanActivate, CanLoad {
constructor(private router: Router,
private route: ActivatedRoute) {}
check(): Observable<boolean> | boolean {
let community = this.route.queryParams["communityId"];
if(community && community!="undefined"){
return true;
}else{
this.router.navigate(['errorcommunity']);
}
return false;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check();
}
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
return this.check();
}
}