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