описать интерфейс canDeactivate
export interface CanDeactivateComponent {
canDeactivate: () => Observable<boolean> | boolean;
}
опишите охрану
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<CanDeactivateComponent> {
canDeactivate(component: CanDeactivateComponent) {
return component.canDeactivate ? component.canDeactivate() : true;
}
}
описать маршрут
path: 'yourPath',
canDeactivate: [CanDeactivateGuard],
component: YourComponent
и компонент:
...
class YourComponent implements CanDeactivateComponent {
...
canDeactivate() {
... everything you need to detect if you can leave route: return false,
or observable
}