Please help me clear my history

$ionicHistory.clearHistory and .clearCache doesn’t work. I have a logout button where I want to clear history and go back to login. Unfortunately the history is not cleared so there is still a back button for dashboard. (It doesn’t actually go to dashboard because the credentials are cleared, but the button is still there and it flashes briefly when I press it) I don’t want that back button. How can I stop that. If I log out from any page and go to login I don’t want a back button. Here is what my logout button does:

$scope.doLogout = function() {
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
AuthService.logout();
loadUserData();
$state.go(‘login’);
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
};

u can use

 $ionicHistory.nextViewOptions({
            disableAnimate: true,
            disableBack: true,
            historyRoot: true
        })

Also worth pointing out that by going to another state from your origin state you are adding history.

Thanks. this works.

Also worth pointing out that by going to another state from your origin state you are adding history.

Ok I (think I) understand that. So if I go to login state I just add another entry to the history, and I don’t actually go back. There is no $state.goBack() or goToRoot(). I was trying to avoid creating a state and just go to the root.

If I understand correctly history here, works differently, its… browser-like. In a native app the back button goes back in the navigation hierarchy up to the parent view. You couldn’t go to a child view using a back button. At least not with a default one.

Yeah, history works as a stack, however if the view you are going back to is the previous state then it doesn’t add it onto the stack…

It gets complicated to explain without diagrams ha