Prevent back button from going back to a page


#1

I have a side menu with many pages attached to it.

states are simply like this:

.state('menu.home', {
	  url: "/home",
	  views: {
		'menuContent' :{
		templateUrl: "home.html"
		}
	  }
	})
    .state('menu.login', {
	  url: "/login",
	  views: {
		'menuContent' :{
		templateUrl: "login.html"
		}
	  }
	})

I have a back button on the menu page.

<ion-nav-bar class="bar-positive"animation="no-animation">
  <ion-nav-back-button class="button-icon ion-arrow-left-c">
  </ion-nav-back-button>
</ion-nav-bar>

Scenario 1: on successful login, $state.go(‘menu.home’, null, {location: ‘replace’});
Problem 1: the ion-nav-back-button still appears, the ‘location replace’ only prevents the actual browser’s back button from going back to the login page.

Scenario 2: if ionic navigation has keep a history like [menu.A, menu.B, menu.C]. Then I go to a form page to submit a request, on success redirect back to menu.C. So history might now be like [menu.A, menu.B, menu.C, menu.search, menu.form]
here, i call $state.go(“menu.C”, {}, { location: “replace” });
clicking on the ion-nav-back-button will bring me back to menu.form
Problem 2: how do i remove [menu.search, menu.form] from the history? or is this a common behavior and not really a problem if the user goes back to the form page?

calling this seems to clear the entire history

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

#2

is this not a common problem? can someone please help?


registerBackButtonAction in a controller blocks the back button in whole app
#3

I am looking for a similar solution to this a scenario like this, have you had any luck?


#4

I had this same situation. I had a form that after submitting successfully I redirect to another view and I don’t want the back button to show up and allow the user to go back to the form again. I found the answer on a github thread

$ionicHistory.currentView($ionicHistory.backView());
$state.go('bla', ..., {location: 'replace'});

You can find the full thread here https://github.com/driftyco/ionic/issues/1287


#5

UI-router replace location doesn’t work well with the way ionic built their history. We have a large app that needs this functionality so I’m trying to push this fix https://github.com/driftyco/ionic/issues/3750