Is there some way how to combine hash and non-hash URLs in Backbone.js application?
I set Backbone.history.start({pushState: true})
. When user click on some link, I fetch JSON data from server, update page, and call Backbone.history.navigate
to change URL in browser from (for example from example.com/zlinsky/kampan/mf/
to example.com/moravskoslezsky/kampan/mf/
).
If user copy URL from browser and open in second tab, he will see same page (so every page updated this way have corresponding page on server). This is exactly what I want.
But now I have problem...
I have several <select>
on page too. When user change value in them, I make some dynamic changes on page (without fetching JSON from server, updates is done only on client side). I would like change URLs according to <select>
, for example to example.com/moravskoslezsky/kampan/mf/#state1
(so, when somebody send this URL, the other side will see same page, in same state as sender).
I could not find way, how to do it in Backbone.js. If I set pushState: true
on Backbone.history
, Router
ignore hash tags.
If I set pushState: false
, I am not able to set URLs like I describe in first paragraph above.
Thank you for any hint.
You can call:
Backbone.history.navigate( "/foo/bar#fragment" )
But i don't think it's a good idea, because ie doesn't support pushstate, so backbone is going to use hash bang urls (in ie).
Maybe you could use querystrings: Backbone.history.navigate( "/foo/bar?foo=bar", true )
which will be in modern browsers: http://domain.tld/foo/bar?foo=bar
and in ie: http://domain.tld#/foo/bar?foo=bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With