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()); } /**