Combine hash and non-hash URLs in Backbone.js

Is there a way to combine hash and non-hash in Backbone.js app?

I installed Backbone.history.start({pushState: true}) . When the user clicks on any link, I get JSON data from the server, the update page and call Backbone.history.navigate to change the URL in the browser (for example, from example.com/zlinsky/kampan/mf/ to example.com/moravskoslezsky/kampan/mf/ ).
If the user copies the URL from the browser and opens in the second tab, he will see the same page (therefore, each updated page has a corresponding page on the server). This is exactly what I want.

But now I have a problem ...

I have several <select> on the page. When the user changes the value in them, I make some dynamic changes on the page (without extracting JSON from the server, updates are performed only on the client side). I would like to change the URLs according to <select> , for example, to example.com/moravskoslezsky/kampan/mf/#state1 (so when someone sends this URL, the other side will see the same page in the same state as the sender).

I could not find a way to do this in Backbone.js. If I set pushState: true to Backbone.history , the Router ignore hash tags.
If I set pushState: false , I cannot set the URLs as described above in the first paragraph.

Thanks for any hint.

+7
source share
1 answer

You can call: Backbone.history.navigate( "/foo/bar#fragment" )

But I do not think that this is a good idea, because i.e. does not support pushstate, so the spine will use hashing URLs (i.e.).

Perhaps you could use querystrings: Backbone.history.navigate( "/foo/bar?foo=bar", true ) , which would be in modern browsers: http://domain.tld/foo/bar?foo=bar and in ie: http://domain.tld#/foo/bar?foo=bar

+2
source

All Articles