feat: remove a particular view from the history
Type: feat
Platform: mobile webview
Say i have traversed 3 views and i have a history that looks like this: A -> B -> C and i am now on C:
Is there currently a way that i can remove B completely from the history - including the cached elements and scope? This would mean going back goes to A
The goBack([amount]) method works perfectly in some situations, but it doesn't work with iOS swipe to go back. A better solution would be a method to remove a specific item in the current history.
If you want to prevent the user to nav back to the last state you can always use $ionicHistory.goBack() before navigating to an other state.
Something like : $ionicHistory.goBack(); $state.go('app.home');
It is not as flexible as being able to remove a particular page though, but in my case it was enough.
+1
+1
+1
+1
+1
+1
+1
+1
+1
I think it is necessary. +1
+1
+2
This will be a part of tonight's nightly build. No further +1s needed 👍 . Thanks for contribution everyone!
Thanks, Dan
I had the issue of deleting a portion of the backviews e.g. I navigate to an application and want to delete the history of the application, but not how I get there. So if I do A -> B -> C ->C1->C2->C1->C2->C3->C1->C4->C , I want the backview of "C" to be "B" (and of "B" to be "A") instead of C4. So I found this post https://calendee.com/2015/04/09/replacing-the-backview-in-ionic-framework/ And by my search of how to accomplish the goal, I came out with this code that so far works great. I hope it's usefull
function ReturnToState( state ){
for( var viewObj in $ionicHistory.viewHistory().views )
{
if( $ionicHistory.viewHistory().views[viewObj].stateName == state ){
console.log( 'Reverted to state: ', state , $ionicHistory.viewHistory().views[viewObj] );
$ionicHistory.backView($ionicHistory.viewHistory().views[viewObj]);
}
}
};
Calling removeBackView() twice returns error:
TypeError: Cannot set property 'backViewId' of undefined
Ah, I think this line:
currentHistory.currentCursor += -1;
should be...
currentHistory.cursor += -1;
Have the same issue with @cjlucani, is there any update on this? did you find another proper way to solve this?
Basically if we would have something like the finish() method in Android Activity, it would be perfect.
I think I have a related issue because I need to remove a particular view from the history, specifically the forwardView. My situation/navigation is this: ion1 -> ion3 -> (stateParam A sent to the view) ion5 -> ion3 -> (stateParam B sent to the view) ion5 -> ion7 -> ion5, where I end with the previous ion5 view (with stateParam A) from the history. I know that if I use a cached view on ion5 this problem doesn't appear, but I can't use cached view here for some other reasons. What I want to do is to remove the forwardView (ion5) from the histories stack first time I go back to ion3, so a new ion5 (it will get other number, but for reference) view with the correct stateParam is saved in history.
Any thought about achieve that? The other workarounds commented here don't apply to this need because I don't want to remove any backView.
+1