Search code examples
jquerybackbone.js

Can I use jQuery pjax with backbone.js


Can I use jquery-pjax with backbone.js?

From what I can see the routing with backbone.js is done with hashes in the url, however jquery-pjax seems to do away with the need for hases for changing the state of a site/app.


Solution

  • You need to enable push state for Backbone to lose the hashes if supported

    Backbone.history.start({pushState: true});

    Edit: To clarify, neither library's will make push state work in older browsers that doesn't support it, they use fallback behaviours. There are two ways to support older browsers, either you use hashes as Backbone does and this provides a more consistent experience. With pjax you will have to hard load the url which is not ideal within the Backbone paradigm, resulting in having to build multiple separate pages for every possible route your backbone app would have.