【发布时间】:2018-11-30 10:47:00
【问题描述】:
如何防止 Angular 路由干扰来自 Express 节点服务器的路由?
我正在我的 Express 服务器中设置一些路由(到 node-RED 中间件):
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'));
});
但在我的路由器模块中,它们总是被覆盖(我们没有默认路径重定向)
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"
},*/
];
我只提供这个小代码,因为我想问一般情况如何防止 Angular 干扰 Express 服务器中定义的路由,以及在 Express 中路由的最佳实践是什么/ Node.js + Angular + AspNetCore + Webpack 应用程序。
【问题讨论】:
标签: node.js angular express webpack angular2-routing