0
votes

When I go to any menu page and click on hardware back button , the app closes instead of going to the previous screen? I am using

<ion-side-menus enable-menu-with-back-views="false">

Can anybody help me with this?

Note : this happens only with the menu page.

I want the the previous screen to appear when hardware back is pressed. Now, back button just closes the app.

Ionic -v : 1.7.7 cordova -v : 5.3.3

Update the problem is with menu-close directive that is being used in the menu list.

  <ion-list>
            <ion-item menu-close nav-clear ui-sref="menu.home">
                    Home
                </ion-item>
                <ion-item menu-close nav-clear ui-sref="menu.welcome">
                    Settings
                </ion-item>
                <ion-item menu-close nav-clear>
                    Profile
                </ion-item>                 
  </ion-list>

I replaced that with menu-toggle="left" . Doing this replaces the menu icon with a back key which is undesired. Any way I can make it like all the other native android app behave?

1

1 Answers

0
votes

if you like to override your mobile device hadware button you can try this in your controller

$ionicPlatform.registerBackButtonAction(function(e) {
    //do your stuff
    if($state.current.name=="login") {
        console.log(e);
     e.preventDefault();
     alert('login');
     //navigator.app.exitApp();
    }
    else{

      $ionicHistory.goBack();

      // in case you find no history just do the following
      // $state.go('previous page state'); this will take you to the page you expected.
    }

    }, 101);

It works for particular page but if you like to do it globally you can use it in .run function.

here e.preventDefault(); this one makes your mobile device hardware backbutton disable .