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.
I added this method under goBack in $ionicHistory and it seems to be working perfectly, but would be good to get some feedback from the ionic team...
/**
* @ngdoc method
* @name $ionicHistory#removeBackView
* @description Remove the previous view from the history completely, including the
* cached element and scope (if they exist).
*/
removeBackView: function () {
var self = this;
var currentHistory = viewHistory.histories[this.currentHistoryId()];
var currentCursor = currentHistory.cursor;
var currentView = currentHistory.stack[currentCursor];
var backView = currentHistory.stack[currentCursor - 1];
var replacementView = currentHistory.stack[currentCursor - 2];
// fail if we dont have enough views in the history
if (!backView || !replacementView) {
return;
}
// remove the old backView and the cached element/scope
currentHistory.stack.splice(currentCursor - 1, 1);
self.clearCache([backView.viewId]);
// make the replacementView and currentView point to each other (bypass the old backView)
currentView.backViewId = replacementView.viewId;
currentView.index = currentView.index - 1;
replacementView.forwardViewId = currentView.viewId;
// update the cursor and set new backView
viewHistory.backView = replacementView;
currentHistory.currentCursor += -1;
},
Probably going to make this a bit more generic like removeFromHistory(stateName)
Eg: removeFromHistory('app.main.createPost') to remove any previous history entries and cached views with that state name.
Anybody interested?
I'd like to see a PR where you can remove previous states by state name and possibly also by ID.
This is a very sensitive area though and would need lots of unit tests and a few HTML tests. If anyone wants to start a PR, I can get it up to snuff so it's ready to be submitted to the core.
Is there any more demand for this?
If you google "ionic location replace" and similar there are quite a lot of people having this issue. PR is coming tonight...
Greetings @Deminetix!
I've closed this issue because my sensors indicated it was old and inactive, and may have already been fixed in recent versions of Ionic. However, if you are still experiencing this issue, please feel free to reopen this issue by creating a new one, and include any examples and other necessary information, so that we can look into it further.
Thank you for allowing me to assist you.
Hi,
I think this is related to #1287 and can be used to fix that problem instead of using any kind of "hack".
Has this been integrated in the core yet or are work-a-rounds still required?
@MoPHL Workarounds are still required, unfortunately.
Would be great if this would make it to core - playing around with these workarounds and there is always something broken :/
+1
+1
+1
+1
+1
+1, this is very major problem for us
+1
+1
+1
+1
+1