Skip to content
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

Backbone.history.start's atRoot var is incorrectly set to false if there is a location.search present #1695

Closed
fishmongr opened this issue Oct 2, 2012 · 3 comments

Comments

@fishmongr
Copy link

In my experience window.history.start's pushState option should be called something like autoUpdateDeepLink as pushState is a loaded word specific to compatible browsers and the Backbone behavior seems to not only enforce html5 push state if this option is passed but also convert push state urls into hash urls for browsers that don't support push state. I've seen examples online where people hook up this flag to Modernizr.history so it gets set to false for IE which makes sense with the current variable name but not the behavior I am seeing.

In that context of setting pushState to true for IE to get the hash url to auto update I am finding everything works great except if you pass querystring variables along with you hash URL Ex:

http://test.url.net/#portfolio/PyUP6R9 works fine
http://local.pathbrite.net/?asdf=sdfsdf#portfolio/PyUP6R9 redirects to http://local.pathbrite.net/?asdf=sdfsdf#.

I tracked this strange behavior to:
var atRoot = (loc.pathname == this.options.root) && !loc.search;
in the Backbone.history.start method. Its set to always expect the web app is not at site root if there is a querystring present which does not make any sense to me. In my context a querystring for analytics is present which should not effect Backbone's atRoot logic. My solution was to comment out the && !loc.search.

TLDR: It seems Backbone.history.start only considers you at web app root if you don't have a querystring present. This is causing my IE urls with querystring+hash to lose the hash value.

@braddunbar
Copy link
Collaborator

Good morning @fishmongr, thanks for pointing this out! Given that Backbone ignores the search parameters in every other area, including a transition in the opposite direction, I agree that it should be ignored in this case. I've addressed this in #1696, please let me know if it doesn't work for you.

jashkenas added a commit that referenced this issue Oct 2, 2012
Fix #1695 - Ignore location.search during pushState transition.
@fishmongr
Copy link
Author

Great, thanks for the speed on that patch! I verified the patch fixed the issue for me. I diff'd my version of Backbone 0.9.2 and noticed there were a ton of other changes since I last downloaded this version. Shouldn't the version number be changing to signify these code changes?

@jashkenas
Copy link
Owner

Yep -- the next released version of Backbone will probably be 0.9.9...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants