Last active
January 29, 2016 18:40
-
-
Save JosephScript/8f854fbe8f5e368d7a98 to your computer and use it in GitHub Desktop.
"Catchall" router for angular apps. Include this router LAST.
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 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