Account for Backbone.js pushState routes with node.js express server? Account for Backbone.js pushState routes with node.js express server? express express

Account for Backbone.js pushState routes with node.js express server?


Explanation

First, you need to know that domain.com/#/about will call the '/' route of your server because it doesn't read the # fragment. Your server will render the base of your Backbone.js application and Backbone will trigger the 'about' route.

So, you need to declare two routes in Express JS:

  • /
  • /about

Code

app.get('/', function(req, res) {    // Trigger the routes 'domain.com' and 'domain.com/#/about'    // Here render the base of your application});app.get('/about', function (req, res) {    // Trigger the route 'domain.com/about'    // Here use templates to generate the right view and render});

I recommend you 3 links for SEO compatibility with Backbone.js by Derick Bailey: