Created
August 20, 2012 10:33
-
-
Save nickpoorman/3402977 to your computer and use it in GitHub Desktop.
Express.js Backbone.js pushState router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if the resource is not found then forward to backbone's router | |
app.use (req, res) -> | |
newUrl = req.protocol + '://' + req.get('Host') + '/#' + req.url | |
res.redirect newUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if the resource is not found then forward to backbone's router | |
app.use(function(req, res) { | |
var newUrl = req.protocol + '://' + req.get('Host') + '/#' + req.url; | |
return res.redirect(newUrl); | |
}); |
This proved to be quite helpful. Thanks for posting this! I especially appreciate that your gist written both in Java- and CoffeeScript. Very considered.
Am I wrong or this actually make a page refresh?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Out of curiosity - how did you get around routes that don't exist for a 404 error?