Skip to content

Instantly share code, notes, and snippets.

@bfricka
Created March 29, 2014 22:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfricka/9864288 to your computer and use it in GitHub Desktop.
Save bfricka/9864288 to your computer and use it in GitHub Desktop.
Sails.js + AngularJS: Supporting HTML5 routing.
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