Clear navigation history stack

How do I clear navigation history stack? Can I achieve that?

1 Like

You should be able to use $ionicHistory.clearHistory() but I haven’t personally used it. I use the following code to set the next view to the root, like when I am going to the home view.

$ionicHistory.nextViewOptions({
     disableAnimate: true,
     historyRoot: true
});
1 Like

I tried that but it did not work.
I used $ionicViewService.clearHistory() and it worked.
Has this been changed?

Oh sorry. $ionicViewService was deprecated in beta 14. I assumed you were using the most recent version.

Thanks!
Another thing: how can I set a back button function in a view to always go back to a fixed specified view?

You could you override the ng-click function of the back button? I still don’t know what version of Ionic you’re using.

<ion-nav-back-button class="button-clear"
ng-click="goBack()">
</ion-nav-back-button>

Then in the goBack function you use $state.go(‘view’)

I`m using the last version but this code did not work.

Can you help me???

Check out this codepen: http://codepen.io/anon/pen/emWOoQ

It is using the latest beta (beta 14) and it is calling the function goBack() which I defined in the back-button. If you open the console you will see it logs “going back” and it is always redirecting to the contact page. You would have to modify this code to go to the state you want and only affect a specific state.

Thanks.
clearHistory does not seem to work any more on beta 14 (I did move to $ionicHistory).
The historyRoot option does the trick.

1 Like

“deprecated” must mean “still working until removed”, must not it?.. Have you broken $ionicViewService with marking it as “deprecated”? Well, it can be excused only in beta…

I’m not sure what you’re saying. I am just reiterating where it was stated as deprecated in this post. If it is still working that is something the Ionic team would have to address.

Oh, I’ve read a comment from @thiago as ‘it stopped working’ and have been disappointed. Sorry to blame you. Our app is still $ionicViewService dependant, and we are not going to switch to $ionicHistory util view service is removed completely. So, it’s quite sensitive for me.

Thanks @brandyshea! after trying different variation of $ionicHistory.clearHistory(); and $ionicHistory.clearCache(); on enter and on leave, your solution is the only one that worked for me

1 Like