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

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”

1 Like

I’m using this command to clear history:


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…

finally I found the answer in a small weird page:

         disableBack: true

that’s all!!!


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

I hope I could help…

I have this on the login function:

$scope.login = function () {

    Security.login($, $scope.cred.password)
        .success(function(data) {
                disableBack: true
            $state.go('posts', {}, {location: "replace", reload: true});
        }).error(function(data) {

and in the logout

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

tell me if it worked for you…

1 Like

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?

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 :smile:

great good too know.

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

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.

:sweat_smile: :sweat_smile: No i am using v5

Please provide your ionic info


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 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)


cordova-res : 0.8.1
native-run : 0.3.0


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