[SOLVED] How-to exclude route from history


#1

Hi,

Is there a way to exclude a route from the history stack?

Example: (where -> = state.go)

route1 -> route2 -> route3 -> route2

If I then click the “Back” button on the “route2” I want to be forwarded to “route1” and not to be forwarded back to the route3.

Tried:

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

no success

Tried:

$state.go(‘route2’, null, { location: ‘replace’ });

no success

Any ideas?

Thx in advance


#2

Hi

Try with goBack

$ionicHistory.goBack([backCount]);

You can go back n views like this : `$ionicHistory.goBack(-n);

backCount is optional negative integer setting how many views to go back. By default it’ll go back one view by using the value -1. To go back two views you would use -2. If the number goes farther back than the number of views in the current history’s stack then it’ll go to the first view in the current history’s stack. If the number is zero or greater then it’ll do nothing. It also does not cross history stacks, meaning it can only go as far back as the current history.


#3

Thx Destroy, that’s a pretty good idea. With it I’m almost there

Now

route1 -> route2 -> route3 .> route2

where -> = state.go and .> = $ionicHistory.goBack()

the history is maintained as excepted. When I land on the last “route2”, if I perform another “Back” button click, I’ll land then on “route1”, perfect.

Now, from “route3” to “route2” I want to pass some parameters thru stateParams

so I tried then

$ionicHistory.backView().stateParams = {
lat: lat, lng: lng
};
$ionicHistory.goBack();

but strangely, adding the stateParams, change the behavior. When I land on “route2”, if I perform a back button click, then I’ll no more land on “route1” but on “route3” ?!!?

any clue?


#4

Solved with the help of a service finally.

On the action in ‘route3’ I do:

MyService.setLastValue(myValue);
$ionicHistory.goBack();

And in ‘route2’:

$scope.$on(’$ionicView.loaded’, function() {
var selectedValue = MyService.getLastValue();

});

and since I use ‘$ionicView.loaded’, added cache-view=“false” to reload it after coming back

Good, let’s move forward