Clear History on View Navigation

Hey,

I have a flow in my app where users are signing up. What i want to do it make it so that once they have hit the final “done” button and the account created, the history is cleared/reset.

Currently i am running this flow by changing state.

In my searching I have found “$ionicViewService.clearHistory();” this seems to work however it seems to be too late when i try it and there is still a back button.

I then tried the events below. These seemed to work as well but again too late. The view shows the back button but it doesnt go anywhere. What do i do to “refresh” or start another user flow. I feel this has got to be simple so I know i must be missing something.

    $scope.$on('$ionicView.leave', function () {
    $ionicViewService.clearHistory();
});
$scope.$on('$ionicView.beforeLeave', function () {
    $ionicViewService.clearHistory();
});
$scope.$on('$ionicView.afterLeave', function () {
    $ionicViewService.clearHistory();
});
$scope.$on('$ionicView.enter', function () {
    $ionicViewService.clearHistory();
});

Any help or advice would be greatly appreciated.

Dale

I may be misunderstanding you, but this will reset the history stack so the next view is the root of the stack:

$ionicHistory.nextViewOptions({
     historyRoot: true
});

I call it before navigating to my home page.

3 Likes

Hahaha i knew it’d be simple. Thanks for that. It’s always fun/hard looking for those simple/easy snippets. Will put that one in my back pocket :smile:

1 Like