Search code examples
javascriptbackbone.jsurl-routingmarionettehashchange

Backbone.JS or Marionette.JS Routing without hash change dependency


I want to start using JavaScript frameworks - and thought I would try Backbone or Marionette as it is very modular and flexible (from what I can tell).

The only thing that is bothering me at the moment is that they both seem to depend on Routing through hash changes. This is not something I can use, as I have a strict URL structure.

Is there a simple way to change this? Like the template tags in Underscore.JS - or is it a little more tricky?

One problem I have is that I am not using Node.js, this is a traditional server set up on Apache (in case the answers rely on Node).

Every example / tutorial I have seen/read/watched/followed depends on the hash change as they are single page web apps. Is this the design of Backbone and Marionette? I can deal with no page refreshes - but need the URL's to change to traditional MVC style ones


Solution

  • You need to enable pushState. And it will only work in modern browsers

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

    Backbone.Router and Backbone.History