# Prevent back button from going back to a page

**URL:** <https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482>\
**Category:** uncategorized\
**Created:** [November 11, 2014, 5:20am UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482 "2014-11-11T05:20:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crosscourt](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@crosscourt](https://forum.ionicframework.com/u/crosscourt)\
**Post date:** [November 11, 2014, 5:20am UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482/1 "2014-11-11T05:20:42Z")

</div>

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
      });
```

---

<div class="post-metadata">

**Author:** ![crosscourt](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@crosscourt](https://forum.ionicframework.com/u/crosscourt)\
**Post date:** [November 13, 2014, 8:10am UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482/2 "2014-11-13T08:10:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marshallbu](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/marshallbu/32/68467_2.png) [@marshallbu](https://forum.ionicframework.com/u/marshallbu)\
**Post date:** [December 21, 2014, 7:12pm UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482/3 "2014-12-21T19:12:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mverdi](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mverdi](https://forum.ionicframework.com/u/mverdi)\
**Post date:** [February 2, 2015, 11:58pm UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482/4 "2015-02-02T23:58:55Z")

</div>

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](https://github.com/driftyco/ionic/issues/1287)

---

<div class="post-metadata">

**Author:** ![AshConnell](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ashconnell/32/64477_2.png) [@AshConnell](https://forum.ionicframework.com/u/AshConnell)\
**Post date:** [May 17, 2015, 9:12am UTC](https://forum.ionicframework.com/t/prevent-back-button-from-going-back-to-a-page/12482/5 "2015-05-17T09:12:37Z")

</div>

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](https://github.com/driftyco/ionic/issues/3750)
