From 667b36114672ad1af6752944cfe4e7855b485232 Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Mon, 21 Oct 2024 11:04:49 +0200 Subject: [PATCH] MOBILE-4686 user-menu: Fix routes with canLeave cannot leave --- .../features/mainmenu/components/user-menu/user-menu.ts | 4 ++-- src/core/services/navigator.ts | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.ts b/src/core/features/mainmenu/components/user-menu/user-menu.ts index 953565fbe83..1e8545f6d26 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.ts +++ b/src/core/features/mainmenu/components/user-menu/user-menu.ts @@ -208,7 +208,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { * @param event Click event */ async logout(event: Event): Promise { - if (CoreNavigator.currentRouteCanBlockLeave()) { + if (!CoreNavigator.currentRouteCanBlockLeave()) { await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks')); return; @@ -242,7 +242,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { * @param event Click event */ async switchAccounts(event: Event): Promise { - if (CoreNavigator.currentRouteCanBlockLeave()) { + if (!CoreNavigator.currentRouteCanBlockLeave()) { await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks')); return; diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index caf6e364246..13db1c61e9d 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -726,7 +726,13 @@ export class CoreNavigatorService { * @returns Whether the current route page can block leaving the route. */ currentRouteCanBlockLeave(): boolean { - return !!this.getCurrentRoute().snapshot?.routeConfig?.canDeactivate?.length; + const canDeactivate = this.getCurrentRoute().snapshot?.routeConfig?.canDeactivate; + + if (!canDeactivate?.length) { + return true; + } + + return canDeactivate.every(method => typeof method === 'function' && method()); } /**