I'm working on a project with lot of forms pages, I want to give intimation to the end-user whenever they try to navigate to another route without saving their changes. In all the pages I'm using reactive forms something like this
this.mainForm = this.formBuilder.group(...
So can I have one can deactivate Guard for all my components something like this
@Injectable()
class CanDeactivateTeam implements CanDeactivate<... something magic here want to pass component dynamically...> {
constructor() {}
canDeactivate(
component: ...dynamicComponent,
currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot,
nextState: RouterStateSnapshot
): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree {
if(!this.mainForm.dirty) return true;
}
}
is it possible to have the same can deactivate guard for all the pages to prevent form changes?
Thanks in advance.