Created
March 29, 2014 22:46
-
-
Save bfricka/9864288 to your computer and use it in GitHub Desktop.
Sails.js + AngularJS: Supporting HTML5 routing.
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
var STATIC_ASSET_REGEX = /\..*/; | |
var routingTable = { | |
'/foo': true, | |
'/bar': true | |
}; | |
module.exports.routes = { | |
'get /*': function(req, res, next) { | |
// Fast check for static assets | |
if (STATIC_ASSET_REGEX.test(req.path)) return next(); | |
// Optionally create a routing table hash (in case you want more control) | |
// Otherwise, just replace everything below with `return res.view('your/homeView')` | |
if (req.path in routingTable) return res.view('site/index'); | |
// Otherwise move to 404 | |
return next(); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment