Skip to content

Commit

Permalink
MOBILE-4686 user-menu: Fix routes with canLeave cannot leave
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonso-salces committed Oct 21, 2024
1 parent 8ea6c00 commit 667b361
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/features/mainmenu/components/user-menu/user-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
* @param event Click event
*/
async logout(event: Event): Promise<void> {
if (CoreNavigator.currentRouteCanBlockLeave()) {
if (!CoreNavigator.currentRouteCanBlockLeave()) {
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));

return;
Expand Down Expand Up @@ -242,7 +242,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
* @param event Click event
*/
async switchAccounts(event: Event): Promise<void> {
if (CoreNavigator.currentRouteCanBlockLeave()) {
if (!CoreNavigator.currentRouteCanBlockLeave()) {
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));

return;
Expand Down
8 changes: 7 additions & 1 deletion src/core/services/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 667b361

Please sign in to comment.