Remove current state from history


#1

Hi. I’ve a create post page from where user is taken to detail page of the post. Now, if he presses back, he’s taken back to the create post page, whereas I would like him to go back to post listing page from where he came on to create post. Ideally, I’ll have to remove current state from history before I redirect user to post detail page after post is created. How can I do this in my controller?


#2

Anything like this?

$ionicHistory.nextViewOptions({
  disableBack: true
});

Put that in your “create post” controller. If that doesn’t do the trick you could try to override the back button so it goes 2 steps back instead of 1.

    <ion-nav-bar>
      <ion-nav-back-button class="button button-icon ion-arrow-left-c" ng-click="goBack2()">
      </ion-nav-back-button>
    </ion-nav-bar>

And in the controller.

$scope.goBack2 = function(){
   $ionicHistory.goBack(-2);
};

#3

Thanks. But apparently, I no longer need the solution. Btw, I tried the first solution in controller on completion of $http request and it didn’t work.