What is pushState for?
I saw the latest backbone.js (0.5) introduced the pushState option for r开发者_C百科outing.
After reading through https://developer.mozilla.org/en/dom/manipulating_the_browser_history I have to say it is not very clear to me : what pushState is and what exactly it is that pushState brings, in the context of writing a web app with backbone; is it for :
improving urls: to have a 'real', bookmarkable, 'server-reachable' url, as opposed to hashes?
graceful degradation: allow the server to render correct pages without JS enabled ?
both/none of the above, or other reasons ?
Also, what am i doing wrong below ?:
class MyRouter extends Backbone.Router
routes :
'' : 'index'
'#hello' :'hello'
index : -> console.log 'index'
hello: -> console.log 'hello'
new MyRouter
Backbone.history.start pushState: true
When I navigate to http://localhost#hello, the url is changed to http://localhost/#hello, but the callback is not fired ?
Thanks
You don't need the # prefix in your routes table. Try this:
routes :
'' : 'index'
'hello' : 'hello'
As for pushState I think its both of the above. It does mean more work on the server-side than you would have to do with location hash because you are going to have to make sure that your server can serve pages for all those URLs.
精彩评论