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:
- SEO And Accessibility With HTML5 PushState, Part 1: Introducing PushState: http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-1-introducing-pushstate/
- SEO And Accessibility With HTML5 PushState, Part 2: Progressive Enhancement With Backbone.js: http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/
- SEO And Accessibility With HTML5 PushState, Part 3: The Video: http://lostechies.com/derickbailey/2011/10/06/seo-and-accessibility-with-html5-pushstate-part-3-the-video/