How to go back on two view states (something like $window.history.go(-2))?

In Ionic I can go back just using:

var backView = $ionicViewService.getBackView();
backView && backView.go();

The question is how to go to the view before backView? Something like:

var backBackView = $ionicViewService.getView(-2);
backBackView && backBackView.go();

I've found the following to be the quickest way to go backwards when deep in a view stack:


I believe you can call that multiple times in a loop to keep going back in the view history. Of course, you have to inject $ionicHistory in your controller.

After some experiments I ended with next solution:

   var backView = $scope.$viewHistory.views[$scope.$viewHistory.backView.backViewId];
    $scope.$viewHistory.forcedNav = {
        viewId:     backView.viewId,
        navAction: 'moveBack',
        navDirection: 'back'
    backView && backView.go();

It looks bad for me, but successfully resolves the problem. I hope this will help to someone.

Update: Now you could actually call


which is described in ionic's documentation.

This is now available in nightlies using $ionicGoBack(amount)