Revision 54915
Added by Konstantinos Triantafyllou about 5 years ago
isRouteEnabled.guard.ts | ||
---|---|---|
5 | 5 |
CanLoad, |
6 | 6 |
ActivatedRouteSnapshot, |
7 | 7 |
RouterStateSnapshot, |
8 |
Route |
|
8 |
Route, Data
|
|
9 | 9 |
} from '@angular/router'; |
10 | 10 |
import {Observable} from 'rxjs/Observable'; |
11 | 11 |
import 'rxjs/add/operator/filter'; |
... | ... | |
18 | 18 |
|
19 | 19 |
constructor(private router: Router, |
20 | 20 |
private config: ConfigurationService, |
21 |
private propertiesService: EnvironmentSpecificService ) {}
|
|
21 |
private propertiesService: EnvironmentSpecificService) {} |
|
22 | 22 |
|
23 |
check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean { |
|
24 |
const customRedirect = route.data['redirect']; |
|
25 |
let community = route.queryParams['communityId']; |
|
26 |
if (!community && route.data['community']) { // for openaire |
|
27 |
community = route.data['community']; |
|
23 |
check(data: Data, community: string, path: string): Observable<boolean> | boolean { |
|
24 |
const customRedirect = data['redirect']; |
|
25 |
if (!community && data['community']) { // for openaire |
|
26 |
community = data['community']; |
|
28 | 27 |
} |
29 | 28 |
if (!community && typeof document !== 'undefined') { |
30 | 29 |
community = ConnectHelper.getCommunityFromDomain(document.location.hostname); |
... | ... | |
42 | 41 |
} |
43 | 42 |
|
44 | 43 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
45 |
return this.check(route, state.url); |
|
44 |
return this.check(route.data, route.queryParams['communityId'], state.url);
|
|
46 | 45 |
} |
47 | 46 |
|
48 | 47 |
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean { |
49 |
return this.check(null, '/' + route.path); |
|
48 |
const path = '/' + route; |
|
49 |
return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path); |
|
50 | 50 |
} |
51 | 51 |
} |
Also available in: Unified diff
[Trunk|Library]: 1. Add static function to find community from url path. 2. Community guards can now be used as CanLoad guards using functionality of getCommunityFromPath(look at 1).