CanDeactivate
The canDeactivate
guard is different from the rest. Its main purpose is not to check permissions, but to ask for confirmation.
To illustrate this let's change the application to ask for confirmation when the user closes the compose dialog with unsaved changes:
[ Â { Â Â Â path: 'compose', Â Â Â component: ComposeCmp, Â Â Â canDeactivate: [SaveChangesGuard] Â Â Â outlet: 'popup' Â } ]
Where
SaveChangesGuard
is defined as follows:
class SaveChangesGuard implements CanDeactivate<ComposeCmp> { Â constructor(private dialogs: Dialogs) {} Â canDeactivate(component: ComposeCmp, route: ActivatedRouteSnapshot, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â state: RouterStateSnapshot): Promise<boolean> { Â Â Â if (component.unsavedChanges) { Â Â Â Â Â return this.dialogs.unsavedChangesConfirmationDialog...