Ionic 离子角动量中Fn的失活

pgky5nke  于 2023-05-27  发布在  Ionic
关注(0)|答案(1)|浏览(190)

我想在我的Ionic Angular应用程序中实现一个CanDeactivate Guard。我发现,我应该使用新的“CanDeactivateFn”警卫,但我找不到任何信息或一个例子如何做到这一点.有人能给予我举个例子吗?这将是非常有帮助的!

eiee3dmh

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;
}

相关问题