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
I too faced a similar situation for routing through angular components using express, this is how I was able to resolve the routing issue:
Setup for my Nodejs Project:
Created an app.js file for the express server with the following contents:
var express = require('express');
var app = require('express')();
const port = 8090;
app.use(express.static('public'));
app.listen(port,()=>{console.log("App working at port : http://localhost:"+port)});
Running this loaded the Root Component only, from where I had to manually route through different pages using routerLink
. If I instead tried to give the child components directly using URL I got a Cannot GET/{URL}
error.
Fix:
express-http-proxy
package imported asvar proxy = require('express-http-proxy');
app.use(express.static('public'));
app.use('/*',proxy('http://localhost:'+port+'/*'));
This fixed my issue.Apparently there is a more standard fix Refer Link