1 |
57813
|
k.triantaf
|
import {Observable} from 'rxjs';
|
2 |
|
|
import {Injectable} from '@angular/core';
|
3 |
|
|
import {CanDeactivate} from '@angular/router';
|
4 |
|
|
|
5 |
|
|
export interface IDeactivateComponent {
|
6 |
|
|
canExit: () => Observable<boolean> | Promise<boolean> | boolean;
|
7 |
|
|
}
|
8 |
|
|
|
9 |
|
|
@Injectable({
|
10 |
|
|
providedIn: 'root'
|
11 |
|
|
})
|
12 |
|
|
export class CanExitGuard implements CanDeactivate<IDeactivateComponent> {
|
13 |
|
|
|
14 |
|
|
constructor() {
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
canDeactivate(component: IDeactivateComponent): Observable<boolean> | Promise<boolean> | boolean {
|
18 |
|
|
|
19 |
|
|
return component.canExit ? component.canExit() : true;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
}
|