Home:ALL Converter>Prevent Angular 6 router from overriding routes defined in Express Server

Prevent Angular 6 router from overriding routes defined in Express Server

Ask Time:2018-06-21T15:31:40         Author:Dr.Legendaddy

Json Formatter

How do I prevent Angular routing from interferring with routes from an Express Node Server?

I'm setting up some routes ( to node-RED middleware) in my Express server:

server.js

    // Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);

// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);

// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));

// Send all other requests to the Angular app
app.get('*', (req, res) => {

  res.sendFile(path.join(__dirname, 'dist/index.js'));
});

but in my router module they get always overridden ( with our without the default path redirection)

routing.module.ts

const appRoutes: Routes = [
    {
        path: "example-page",
        loadChildren: "../modules/example/example.module#ExampleModule?sync=true"
    },
    // Last routing path specifies default path for application entry
/*    {
        path: "**",
        redirectTo: "/example-page",
        pathMatch: "full"
    },*/
];

I'm only providing this little code because I want to ask in general how do I prevent Angular from interferring with routes defined in an Express server and what is the best practice for routing in an Express/ Node.js + Angular + AspNetCore + Webpack app.

Author:Dr.Legendaddy,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50962826/prevent-angular-6-router-from-overriding-routes-defined-in-express-server
yy