Clear navigation history - Prevent back button use (android)

I want to clear the entire nav history when a user logs out. Currently for my app I can log out which makes it go to the nav screen, I clear the access_token (I am using oauth), delete the access and refresh token on the server and the user can log back on. But if the user presses the back button on their (android) phone they can get back into the app, it’ll look broken because the data won’t be there but I would like to prevent it altogether.

I could do a check and if the access token doesn’t exist, shoot them back to the index page, but I would still like to know how to clear the history in case I need it somewhere else.

I see other topics about hiding the back button, but I don’t think these will do the trick because it’s a hardware back button. My app doesn’t even have an on screen back button.

Thank you,

Thomas Le

2 Likes

See this:

$ionicViewService.clearHistory()

Thank you for your reply. I apologize for not finding that post. I guess I didn’t use the right search terms.

I added that to my code but it didn’t seem to change anything, unfortunately.

I did some digging around the $ionicViewService and found this thing to view the history
$rootScope.$viewHistory.histories. So i threw that in a few console.log()'s around my app and after I call clearHistory() it still remains.

Can you setup a sample we can take a look at?

See Also : The clearHistory() doesn't clear histories data

If either of you can setup a sample, it will speed up the fix.