2017-02-22 18:13:21 +00:00
|
|
|
// #docregion
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { CanDeactivate } from '@angular/router';
|
2018-02-27 17:06:06 -05:00
|
|
|
import { Observable } from 'rxjs';
|
2017-02-22 18:13:21 +00:00
|
|
|
|
|
|
|
export interface CanComponentDeactivate {
|
|
|
|
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
|
|
|
|
}
|
|
|
|
|
2017-10-23 08:11:51 -05:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2017-02-22 18:13:21 +00:00
|
|
|
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
|
|
|
canDeactivate(component: CanComponentDeactivate) {
|
|
|
|
return component.canDeactivate ? component.canDeactivate() : true;
|
|
|
|
}
|
|
|
|
}
|