Skip to content

Instantly share code, notes, and snippets.

@JosephScript
Last active January 29, 2016 18:40
Show Gist options
  • Save JosephScript/8f854fbe8f5e368d7a98 to your computer and use it in GitHub Desktop.
Save JosephScript/8f854fbe8f5e368d7a98 to your computer and use it in GitHub Desktop.
"Catchall" router for angular apps. Include this router LAST.
var express = require('express');
var router = express.Router();
/* handle root angular route redirects */
router.get('/*', function(req, res, next){
var url = req.originalUrl;
if (url.split('.').length > 1){
next();
} else {
// handles angular urls. i.e. anything without a '.' in the url (so static files aren't handled)
console.log('Catch all handled url: ' + url);
res.redirect('/#' + url);
}
});
console.log('Route * loaded.');
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment