Reputation: 6657
I have the following problem. Some part of my Backbone application has url like:
site.ru/#profile
When the page is loaded URL changes to:
site.ru/profile
So, the hash was lost. So, I see the problem in navigate function of Backbone:
var routeStripper = /^[#\/]/;
...
var frag = (fragment || '').replace(routeStripper, '');
As I understand this code clean a hash at the begin of URL.
Is it true way to simply delete this line of code to fix the problem? Could you advise me some other ways to fix this.
TIA!
Upvotes: 10
Views: 6944
Reputation: 1060
Having the same issue, and some others with us ;-) (see GitHub issue)
I've fixed this for now by not listening to hash changes, like so:
Backbone.history.start({
pushState: true,
hashChange: false,
root: '/'
});
This seemed to work for me.
Upvotes: 0
Reputation: 47833
Backbone only removes the hash if you enable pushState.
Change Backbone.history.start({pushState: true});
to Backbone.history.start();
Upvotes: 12
Reputation: 1155
Seems Backbone.js is using / & # as delimiters, to pull out the root address & sub-directories. The / filtering needs tp stau tp get the "fragment". Try to just delete the # in that RegEx, but leave the rest of the line there. (& leave a comment in the code that you have done so! :)
I would also submit a bug report, since it is resending the link without the hash.
Upvotes: 0