我試圖在同一臺服務器上使用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