我试图在同一台服务器上使用angular2应用程序托管我的快递服务。 阅读相关变化后,我发现变化后的解决方案都解决本地服务器http://localhost:3000上,但我托管在Heroku上的应用程序时,我尝试访问我的快递路线与/ API启动/ ... ...所有运作良好。但无法访问它开始在页面上显示Not Found消息的angular2 UI页面。如何使angular2路由与express路由器一起工作?
app.all('*', (req, res) => {
console.log(`[TRACE] Server 404 request: ${req.originalUrl}`);
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
或
app.use(function(req, res, next) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
或
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
或
app.get(/^\/([^a]|a[^p]|ap[^i]|api[^/]).*$/,(req,res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
什么是“我想访问我的快递路线与/ API开始部署/ ...一切运作良好,但无法访问angular2 UI它开始在页面上显示Not Found消息。“意思?什么不起作用? – echonax
它没有显示我的angular2应用程序登录页面。 –
这几乎是不可能猜测错误是基于你给出的信息。请分享你的文件夹结构,你的路由细节,也许你的Heroku的网址,如果它不是私人 – echonax