[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:
parent
90c1ef5c41
commit
80a3c32173
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue