[Library]: Add can exit guard

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57813 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-12-04 18:24:40 +00:00
parent 90c1ef5c41
commit 80a3c32173
1 changed files with 22 additions and 0 deletions

22
utils/can-exit.guard.ts Normal file
View File

@ -0,0 +1,22 @@
import {Observable} from 'rxjs';
import {Injectable} from '@angular/core';
import {CanDeactivate} from '@angular/router';
export interface IDeactivateComponent {
canExit: () => Observable<boolean> | Promise<boolean> | boolean;
}
@Injectable({
providedIn: 'root'
})
export class CanExitGuard implements CanDeactivate<IDeactivateComponent> {
constructor() {
}
canDeactivate(component: IDeactivateComponent): Observable<boolean> | Promise<boolean> | boolean {
return component.canExit ? component.canExit() : true;
}
}