Trying to understand $state.go('^') and $ionicViewService


Hi, apologies if this is going over old ground but having read numerous posts on the correct use of ui-router and transitioning across states i’m getting more and more confused as to what expected behaviour should be.

In some parts of my app, calling $state.go(’^’) correctly reverses the left-right transition and traverses back up the history stack to display the correct view. This led me to assume that the $ionicViewService can intelligently look at the state being transitioned to and if it exists within history stack ‘reverse’ back to that state.

However, in other parts of my app, calling $state.go(’^.^’) to get to a state parent/parent state that is two or three levels back in the history stack actually goes ‘forward’ and creates a new entry in the history stack.

I am unable to find any documentation on $ionicViewService so have looked at the source code but i’m still a bit lost.

Is there an expected behaviour in regards to navigating through various levels of the history stack and is there any documentation I can read to ensure i’m using the nav-view concept correctly?


well, after a lot more research and finding some useful entries i’d missed before I have found a way to do this.

var view = $ionicViewService.getCurrentView();

$scope.$viewHistory.forcedNav = {
	viewId: view.viewId,
	navAction: 'moveBack',
	navDirection: 'back'

This certainly works, although as its undocumented I suppose there is a risk it will break in the future, for now, all is good!