-
Notifications
You must be signed in to change notification settings - Fork 3k
Preserve url fragment on page reload #612
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
closed pending comments #510 |
You don't have to close a pull request while waiting on comments elsewhere. |
Thanks for the FYI @timkindberg. I'd happily make preserveHash an option on the |
I'll probably comment over there, but I'm now curious, when would you NOT want to preserve a hash? I think never. |
Well, transitionTo() is used for both state changes and "redirects" (e.g., when you navigate to a URL that matches a state, but includes extra text and the router rewrites the URL to something that matches the state exactly). In the latter case, you obviously want to preserve the hash, but in the former case, you probably don't. Otherwise, you'd be transitioning to a completely new state but still inheriting the hash from the previous one. |
@beyang It sounds like we may need to factor out a different method for that then. |
@nateabele, I'm not sure I follow. 2 questions: |
Correct, the hash is logically separate from
After re-reading the discussion, I actually don't remember what I had in mind when I left my previous comment. What makes the most sense to me right now is to begin factoring out the relevant portions of Since this issue only affects the initial page load, the initial page load just needs a slightly different code path, which can call these functions directly, rather than adding a parameter to an already very complex & highly parameterized public method. Let me know if the above makes sense. |
@nateabele, upon closer observation, this seems to be a bug-fix, not a feature :) The first couple of lines of transitionTo were a little too clever, and the function was not respecting the "updateLocation" semantics of the options param (https://github.com/angular-ui/ui-router/wiki/Quick-Reference#updatelocation-or-options). On initial state registration, updateLocation is set to false for the exact purpose that it doesn't want to overwrite the URL (and the hash along with it). This PR fixes that issue and adds a test for it. |
@beyang Ohhhkay, I think I see now.
Definitely agreed on that count.
Nope, actually, allowing Rather, the correct fix would be to change the $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
$state.transitionTo(state, $match, { location: false });
}
}]); I'll let you update the patch. The test should be able to remain the same. Please don't forget to squash your commits, and follow the Angular commit message format. Thanks! |
It is deprecated in 0.3 I thought, regardless, it is already on my list of assignments. Hopefully I'll get around to my list here soon. Been very busy lately. |
@timkindberg Don't feel bad, I'll just keep piling things onto your todo list. |
…itionTo() fix hash-overwriting issue on new page load / page reload
@nateabele see the updated PR. thanks! |
@beyang Brilliant, looks great. Thanks for all your efforts on this. |
Preserve url fragment on page reload
thank you for making an awesome library :) |
Are there docs on how to enable this? I have the latest UI Router and named anchors do not work for me when loaded from address bar. |
@cyberwombat I don't think you're asking for the same thing as this PR addresses. What do you mean by named anchors? |
@nateabele - seems like the original entry to this issue describes it. Basically my nameed anchors, i.e. |
This sounds like a server configuration issue, which would be unrelated to UI Router. Please see https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode |
This fixes a bug where the URL hash disappears when a page is first loaded.
For instance, if you had a link
<a href="#someanchor">link</a>
on your page and clicked on it, the link would work correctly (it would scroll to#someanchor
), but if you copied and pasted the URL into a new tab and navigated to the page afresh, the hash would disappear and no scrolling would occur.See also: #510