Paul Smith
Paul Smith

Reputation: 105

Back button not working: $ionicHistory.backView() is the same with currentView

I am using Ionic v1 Angular

Here is my code:

$scope.back = function () {        
    $ionicHistory.goBack();
    // window.history.back(); //this works but not working on device hardware back button
    console.log($ionicHistory.currentView()); //url: app/home
    console.log($ionicHistory.backView()); //url: app/home
};

Here is my button:

<button ng-hide="current_state == 'app.home'" class="button button-clear" menu-toggle="left" ng-click="back()" id="back_button">back</button> 

Upvotes: 1

Views: 184

Answers (1)

Ram_T
Ram_T

Reputation: 8484

If you want to control hardware backbutton you must register and override default action of hardware back button

  // Disable BACK button on home
  $ionicPlatform.registerBackButtonAction(function (event) {
    if($state.current.name=="app.home"){  // if you are in home page you can close the app
      navigator.app.exitApp();
    }
    else { // otherwise you just go back to previous statein the history
      navigator.app.backHistory();
    }
  }, 100);

Upvotes: 1

Related Questions