-
Notifications
You must be signed in to change notification settings - Fork 3k
feat($state): expose previous state/params via $state #1218
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
Conversation
While I think this would make a lot of people happy... I'm reading @nateabele comment from a very similar pull request that was closed. |
please please please :) This is the first google result on how to do this :) |
Yeah, this is piling bad design on top of existing bad design. Sorry. |
I understand, a history service would be more appropriate. This patch will hopefully prove a useful if temporary fix for some in the meantime. Alternatively this snippet (which could go in the F.A.Q. maybe?) might help: // in main controller
$rootScope.$on('$stateChangeSuccess', function(e, toState, toParams, fromState, fromParams) {
$state.previous = fromState;
$state.previousParams = fromParams;
}); |
Fixed that for you: http://plnkr.co/DJH6mQUCbTFfSbdCBYUo Please note that some features have been left as an exercise for the reader (see TODOs). |
Thanks @nateabele, it's... beautiful. I'm not sure I quite understand the TODOs but hopefully it'll become clear. |
@homerjam You bet. The purpose of the TODOs has to do with attempting to mirror the history tracking with the browser's actual history as presented in the dropdown menu of the back button. Since not all states have URLs, there won't be a 1:1 correspondence between However, by being clever and tracking which states have URLs, you could do some tricks to match up one to the other, so that you can properly keep the actual browser's history properly in sync. Hope that makes sense. |
Yes I get what you mean now, I've not really used |
@homerjam Cool, let me know how you get on. |
I cannot find this in version 0.2.11, will it be in the next release? |
@BorisKozo Please note that this PR was closed without being merged. |
I have created my own service to handle this. Please check it out and let me know if any concern comes https://github.com/amitagrawal11/UI-Router-History |
Please please please, fixes #92 and #1100