Wen*_*nto 5 heroku node.js angular2-routing angular
我在 heroku 中有一个 angular2 应用程序,但我遇到了路由器问题。在 localhost 中,一切都像魅力一样,但是当我部署到 heroku 并尝试通过任何不是索引的路由访问时,我收到 404 错误,如果我去索引,然后导航低谷页面路由正常发生,除非我重新加载页面,然后我得到另一个 404,这是 heroku 使用的 package.json 的一部分我
"heroku-prebuild": "npm install http-server -g",
"heroku-postbuild": "ng build --target=production --environment=prod && rsync -a dist/* .",
"start": "http-server dist/",
是否需要设置任何要在我的 Procfile 中使用的快速重写?
这似乎是服务器的问题,角度知道路由,但你的服务器不知道所有这些路径。简单的解决方案是将所有路径重定向到主 index.html 。像这样,
app.get('*', function (req, res) {
res.sendfile('./dist/index.html'); // load our index.html file
});
Run Code Online (Sandbox Code Playgroud)
这不会给出任何 404 错误,您的所有路径将被重定向到主路径,即index.html,并且角度路由将像在本地主机中一样运行。
| 归档时间: |
|
| 查看次数: |
806 次 |
| 最近记录: |