Skip to content

feat: remove a particular view from the history #3750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ashconnell opened this issue May 16, 2015 · 41 comments
Closed

feat: remove a particular view from the history #3750

ashconnell opened this issue May 16, 2015 · 41 comments

Comments

@ashconnell
Copy link

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 ashconnell changed the title remove a particular view from the history feat: remove a particular view from the history May 16, 2015
@ashconnell
Copy link
Author

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
Copy link
Author

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?

@perrygovier
Copy link
Contributor

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 perrygovier added navigation needs: reply the issue needs a response from the user labels May 18, 2015
@ashconnell
Copy link
Author

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

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label May 22, 2015
@Ionitron
Copy link
Collaborator

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.

@pesimeao
Copy link

Hi,

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

@LuisMCunha
Copy link

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

@jakemulley
Copy link

@MoPHL Workarounds are still required, unfortunately.

@janpio
Copy link

janpio commented Nov 21, 2015

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

@jtomaszewski
Copy link

+1

4 similar comments
@carlosjunior
Copy link

+1

@danicomas
Copy link

+1

@ChristopheDaVinci
Copy link

+1

@headchen
Copy link

headchen commented Dec 7, 2015

+1

@fesor
Copy link

fesor commented Dec 14, 2015

+1, this is very major problem for us

@Rondeus
Copy link

Rondeus commented Dec 15, 2015

+1

4 similar comments
@jeremyross
Copy link

+1

@abeniwal
Copy link

+1

@lucasbeef
Copy link

+1

@alwayrun
Copy link

alwayrun commented Jan 1, 2016

+1

@lucasbeef
Copy link

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.

@MarioGallegos
Copy link

+1

@longsangstan
Copy link

+1

7 similar comments
@t0mm13b
Copy link

t0mm13b commented Jan 31, 2016

+1

@rafaelcoutinho
Copy link

+1

@05bca054
Copy link

+1

@agustinjlopez
Copy link

+1

@macno
Copy link

macno commented Mar 1, 2016

+1

@VinceOPS
Copy link

VinceOPS commented Mar 1, 2016

+1

@ghost
Copy link

ghost commented Mar 23, 2016

+1

@flynt7111
Copy link

I think it is necessary.
+1

@NayHaPal
Copy link

+1

@professor-rage
Copy link

+2

@danbucholtz
Copy link
Contributor

danbucholtz commented Apr 15, 2016

This will be a part of tonight's nightly build. No further +1s needed 👍 . Thanks for contribution everyone!

Thanks,
Dan

@MartinFreire
Copy link

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]);
        }
    }
};

@cjlucani
Copy link

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;

@stelioschar
Copy link

Have the same issue with @cjlucani, is there any update on this? did you find another proper way to solve this?

@loolooii
Copy link

loolooii commented Aug 5, 2016

Basically if we would have something like the finish() method in Android Activity, it would be perfect.

@guillermogfer
Copy link

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.

@spixy
Copy link

spixy commented May 27, 2018

+1

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 1, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests