As part of one of the requirements, I need to find if user have pending changes and if he hit back button or hit refresh then need to alert. We are using canDeactivate angular guard to prevent on the single page but we need to do it across all the pages. Hence we are looking for reusable code for all pages. we are exploring it achieving via directive. Any suggestion here much appreciated. Below is our current code for single page check.
@HostListener('window:beforeunload')
canDeactivate(): boolean | Observable<boolean>
{
return (
(!this.NameFormControl.dirty)
}