ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

feat: remove a particular view from the history

Open ashconnell opened this issue 11 years ago • 41 comments

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.

ashconnell avatar May 16 '15 02:05 ashconnell

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;
},

ashconnell avatar May 16 '15 02:05 ashconnell

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?

ashconnell avatar May 17 '15 09:05 ashconnell

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?

perrygovier avatar May 18 '15 16:05 perrygovier

If you google "ionic location replace" and similar there are quite a lot of people having this issue. PR is coming tonight...

ashconnell avatar May 22 '15 08:05 ashconnell

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.

Ionitron avatar Aug 20 '15 11:08 Ionitron

Hi,

I think this is related to #1287 and can be used to fix that problem instead of using any kind of "hack".

pesimeao avatar Aug 21 '15 08:08 pesimeao

Has this been integrated in the core yet or are work-a-rounds still required?

LuisMCunha avatar Oct 08 '15 09:10 LuisMCunha

@MoPHL Workarounds are still required, unfortunately.

jakemulley avatar Nov 05 '15 15:11 jakemulley

Would be great if this would make it to core - playing around with these workarounds and there is always something broken :/

janpio avatar Nov 21 '15 22:11 janpio

+1

jtomaszewski avatar Nov 26 '15 10:11 jtomaszewski

+1

carlosjunior avatar Nov 26 '15 14:11 carlosjunior

+1

danicomas avatar Nov 26 '15 16:11 danicomas

+1

ChristopheDaVinci avatar Nov 30 '15 13:11 ChristopheDaVinci

+1

headchen avatar Dec 07 '15 01:12 headchen

+1, this is very major problem for us

fesor avatar Dec 14 '15 02:12 fesor

+1

Rondeus avatar Dec 15 '15 14:12 Rondeus

+1

jeremyross avatar Dec 15 '15 16:12 jeremyross

+1

abeniwal avatar Dec 19 '15 16:12 abeniwal

+1

lucasbeef avatar Dec 22 '15 13:12 lucasbeef

+1

alwayrun avatar Jan 01 '16 08:01 alwayrun