# Remove page from history, so "back" will work properly

**URL:** <https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378>\
**Category:** ionic-v1\
**Created:** [October 18, 2014, 3:17pm UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378 "2014-10-18T15:17:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tzookb](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tzookb](https://forum.ionicframework.com/u/tzookb)\
**Post date:** [October 18, 2014, 3:17pm UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/1 "2014-10-18T15:17:21Z")

</div>

I have my app that you need to login to get in to the other pages.

so the first page is “login” and it checks if you are already logged, if so you will be redirected to the main page app, if not it will show you the login page.

now the problem is when the user is inside the logged page area, and he clicks back he will get to the “login” page and than redirected back to the main page, as he is logged in already.

So he is stuck in an infinite loop.

how can I remove the login page from the history.

just like in android “android remove activity from history stack”

---

<div class="post-metadata">

**Author:** ![Auro](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Auro](https://forum.ionicframework.com/u/Auro)\
**Post date:** [October 20, 2014, 8:22am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/2 "2014-10-20T08:22:10Z")

</div>

I’m using this command to clear history:

```
    $ionicViewService.clearHistory();
```

---

<div class="post-metadata">

**Author:** ![tzookb](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tzookb](https://forum.ionicframework.com/u/tzookb)\
**Post date:** [October 20, 2014, 7:12pm UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/3 "2014-10-20T19:12:44Z")

</div>

this works nice when I’m checking this on the browser,  
but when I check the app on my android device, it still takes me back…

---

<div class="post-metadata">

**Author:** ![tzookb](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tzookb](https://forum.ionicframework.com/u/tzookb)\
**Post date:** [October 20, 2014, 8:45pm UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/4 "2014-10-20T20:45:42Z")

</div>

finally I found the answer in a small weird page:

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

```

that’s all!!!

---

<div class="post-metadata">

**Author:** ![haibtdt](https://avatars.discourse-cdn.com/v4/letter/h/779978/32.png) [@haibtdt](https://forum.ionicframework.com/u/haibtdt)\
**Post date:** [October 21, 2014, 8:22am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/5 "2014-10-21T08:22:49Z")

</div>

Could show me an example? I don’t know where to put that code, in log-in page or a page after?

---

<div class="post-metadata">

**Author:** ![tzookb](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tzookb](https://forum.ionicframework.com/u/tzookb)\
**Post date:** [October 21, 2014, 8:32am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/6 "2014-10-21T08:32:13Z")

</div>

I hope I could help…

I have this on the login function:

```
$scope.login = function () {

    Security.login($scope.cred.email, $scope.cred.password)
        .success(function(data) {
            Security.setUser(data.data[0]);
            $ionicViewService.nextViewOptions({
                disableBack: true
            });
            $state.go('posts', {}, {location: "replace", reload: true});
        }).error(function(data) {
            $scope.showAlert();
        });
};

```

and in the logout

```
  $scope.logout = function () {
        //perform logout
        Security.logout();
        $ionicViewService.nextViewOptions({
            disableBack: true
        });
        $state.go('login', {}, {location: "replace", reload: true});
    };

```

tell me if it worked for you…

---

<div class="post-metadata">

**Author:** ![haibtdt](https://avatars.discourse-cdn.com/v4/letter/h/779978/32.png) [@haibtdt](https://forum.ionicframework.com/u/haibtdt)\
**Post date:** [October 21, 2014, 8:47am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/7 "2014-10-21T08:47:26Z")

</div>

Excellent, thank you so much. The problem had already left me in pain for last 3 months. UX now no longer suffers.  
Wonder what i am missing when research about angular ui router does not lead me to a solution? Or that’s $ionicViewService fulfills?

---

<div class="post-metadata">

**Author:** ![tzookb](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@tzookb](https://forum.ionicframework.com/u/tzookb)\
**Post date:** [October 21, 2014, 10:13am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/8 "2014-10-21T10:13:28Z")

</div>

I struggled on it for a week, with ui-router etc…

until I found in some weird location this bit of code, and it worked 😄

---

<div class="post-metadata">

**Author:** ![Auro](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Auro](https://forum.ionicframework.com/u/Auro)\
**Post date:** [October 21, 2014, 10:38am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/9 "2014-10-21T10:38:05Z")

</div>

great good too know.

---

<div class="post-metadata">

**Author:** ![shubhamappstec](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@shubhamappstec](https://forum.ionicframework.com/u/shubhamappstec)\
**Post date:** [December 25, 2019, 11:00am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/10 "2019-12-25T11:00:35Z")

</div>

Cannot find name ‘$ionicViewService’. could you help me?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 26, 2019, 12:18am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/11 "2019-12-26T00:18:52Z")

</div>

Hey there. It looks like you’ve responded to an ancient thread involving a really old version of Ionic. Are you sure you’ve got a v1 app? If not, nothing in the “ionic-v1” category is going to be relevant to your situation.

---

<div class="post-metadata">

**Author:** ![shubhamappstec](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@shubhamappstec](https://forum.ionicframework.com/u/shubhamappstec)\
**Post date:** [December 26, 2019, 5:19am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/12 "2019-12-26T05:19:25Z")

</div>

😅 😅 No i am using v5

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [December 26, 2019, 9:57am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/13 "2019-12-26T09:57:13Z")

</div>

Please provide your `ionic info`

---

<div class="post-metadata">

**Author:** ![shubhamappstec](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@shubhamappstec](https://forum.ionicframework.com/u/shubhamappstec)\
**Post date:** [December 31, 2019, 7:56am UTC](https://forum.ionicframework.com/t/remove-page-from-history-so-back-will-work-properly/11378/14 "2019-12-31T07:56:58Z")

</div>

Ionic:

Ionic CLI : 5.4.13  
Ionic Framework : @ionic/angular 4.11.7  
@angular-devkit/build-angular : 0.801.3  
@angular-devkit/schematics : 8.1.3  
@angular/cli : 8.1.3  
@ionic/angular-toolkit : 2.1.1

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)  
Cordova Platforms : android 8.1.0  
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 7 other plugins)

Utility:

cordova-res : 0.8.1  
native-run : 0.3.0

System:

Android SDK Tools : 26.1.1  
NodeJS : v10.16.2  
npm : 6.9.0  
OS : Windows 10
