我想在我的Ionic Angular应用程序中实现一个CanDeactivate Guard。我发现,我应该使用新的“CanDeactivateFn”警卫,但我找不到任何信息或一个例子如何做到这一点.有人能给予我举个例子吗?这将是非常有帮助的!
eiee3dmh1#
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; }
1条答案
按热度按时间eiee3dmh1#