Issue
I would like to implement a CanDeactivate Guard in my Ionic Angular application. I've found out, that I should use the new "CanDeactivateFn" Guard, but I can't found any information or an example how to do it. Can somebody give me an example? That would be very helpful!
Solution
export const GlossaryOutGuard: CanDeactivateFn<GlossaryComponent> =
(
component: GlossaryComponent,
currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot,
nextState: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree =>
{
let sweetAlertService: SweetAlertService = inject(SweetAlertService);
if(component.viewMode == 'GLOSSARY' && component.isSomeMenuItemUnderEdition()) {
let menuItemUnderEdition: EditGlossaryItemComponent = component.getMenuItemUnderEdition()!;
return sweetAlertService
.showGlossaryDataLosingQuestion(menuItemUnderEdition.label!)
.then((result: SweetAlertResult) => result.isConfirmed);
}
return true;
}
Answered By - Bruno Miguel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.