I\'ve got in impasse with setting Angular routes to work with Express.
I tried to do like here Express 4, NodeJS, AngularJS routing but that did not work. The stati
When you don't pass a path to express.use()
, then it defaults to /
. The proceeding rule you set for *
is either redundant or may not even work.
Also, since you're using html5mode
, you need to explicitly set apart routes from resources so Express doesn't try to serve up your index.html
file for all requests.
Try this example from Angular UI-Router on for size:
var express = require('express');
var app = express();
app.use('/js', express.static(__dirname + '/js'));
app.use('/dist', express.static(__dirname + '/../dist'));
app.use('/css', express.static(__dirname + '/css'));
app.use('/partials', express.static(__dirname + '/partials'));
app.all('/*', function(req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: __dirname });
});
app.listen(3006); //the port you want to use