Search code examples
backbone.js

How to replace "#" routes to standard routes


E.g: in router.js

routes: { "": "home", "first": "first" }, .....

in page:

<a href="#">home</a> <a href="#first">link first page</a>

In the browser address bar: www.domain.com/#first

I want to get URL: www.domain.com/first

How to replace the "#" in routes?


Solution

  • You can use Backbone.history.start({ pushState: true }).

    From documentation (http://backbonejs.org/#History):

    To indicate that you'd like to use HTML5 pushState support in your application, use Backbone.history.start({pushState: true}). If you'd like to use pushState, but have browsers that don't support it natively use full page refreshes instead, you can add {hashChange: false} to the options.