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
While the solution suggested by @kirgol of using base href=
works fine, there is an alternative solution which might interest someone looking for simple route serve. In this solution we will not using ExpressJS routing
Simply use this
app.use(express.static(__dirname + '/app'));
instead of this
app.all('/*', function(req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: __dirname });
});
This way expressJS will automatically serve the index.html present at that static location & will handle the routing automatically. It will behave just like a simple http server. The moment you handle the routing using app.all
/ app.get
- you will have to set base href
to tell $locationProvider
of location from which it can match routes