How do I clear navigation history stack? Can I achieve that?
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
});
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.
â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