1
|
import { Injectable } from '@angular/core';
|
2
|
import {
|
3
|
Router,
|
4
|
CanActivate,
|
5
|
ActivatedRouteSnapshot,
|
6
|
RouterStateSnapshot,
|
7
|
Route,
|
8
|
CanLoad
|
9
|
} from '@angular/router';
|
10
|
import {Observable} from 'rxjs';
|
11
|
import {LoginErrorCodes} from './utils/guardHelper.class';
|
12
|
|
13
|
@Injectable()
|
14
|
export class FreeGuard implements CanActivate {
|
15
|
|
16
|
constructor(private router: Router) {
|
17
|
}
|
18
|
|
19
|
check(path: string): boolean {
|
20
|
const valid = true;
|
21
|
if (!valid) {
|
22
|
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': path}});
|
23
|
}
|
24
|
return valid;
|
25
|
}
|
26
|
|
27
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
28
|
return this.check(state.url);
|
29
|
}
|
30
|
|
31
|
}
|