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

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.

lucasbeef avatar Jan 02 '16 16:01 lucasbeef

+1

MarioGallegos avatar Jan 04 '16 22:01 MarioGallegos

+1

longsangstan avatar Jan 30 '16 09:01 longsangstan

+1

t0mm13b avatar Jan 31 '16 00:01 t0mm13b

+1

rafaelcoutinho avatar Feb 16 '16 14:02 rafaelcoutinho

+1

05bca054 avatar Feb 16 '16 15:02 05bca054

+1

agustinjlopez avatar Feb 19 '16 01:02 agustinjlopez

+1

macno avatar Mar 01 '16 16:03 macno

+1

VinceOPS avatar Mar 01 '16 17:03 VinceOPS

+1

ghost avatar Mar 23 '16 15:03 ghost

I think it is necessary. +1

flynt7111 avatar Mar 29 '16 07:03 flynt7111

+1

NayHaPal avatar Mar 30 '16 15:03 NayHaPal

+2

professor-rage avatar Apr 14 '16 21:04 professor-rage

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

Thanks, Dan

danbucholtz avatar Apr 15 '16 15:04 danbucholtz

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

MartinFreire avatar May 09 '16 12:05 MartinFreire

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;

cjlucani avatar May 31 '16 12:05 cjlucani

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

stelioschar avatar Jun 01 '16 14:06 stelioschar

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

loolooii avatar Aug 05 '16 01:08 loolooii

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.

guillermogfer avatar Aug 31 '16 11:08 guillermogfer

+1

spixy avatar May 27 '18 09:05 spixy