我已经在Heroku上部署了angular 8应用程序。单击它们时,它的路线工作正常,但是 在浏览器中手动键入它们时,返回404错误。
请帮助。提前谢谢!。
答案 0 :(得分:0)
I've fixed this issue by modifying server.js code:
const express = require('express');
const app = express();
// Run the app by serving the static files
// in the dist directory
app.use(express.static(__dirname + '/dist/project-folder'));
// Start the app by listening on the default
// Heroku port
app.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/project-folder');
});
app.listen(process.env.PORT || 8080);
==============================================
**Modified code is below which fixed the issue:**
===========================================
const express = require('express');
const app = express();
// Run the app by serving the static files
// in the dist directory
app.use(express.static(__dirname + '/dist/project-folder'));
// Start the app by listening on the default
// Heroku port
app.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/project-folder/index.html');
});
app.listen(process.env.PORT || 8080);