Angular CLI 路由 - 不适用于(Apache-)服务器
我目前正在为一个项目学习 Angular-CLI.我成功地用一些路由对象创建了一个简单的小项目.在带有 ng serve 的开发模式下,一切正常.我可以在浏览器中调用 localhost:port 并且它与路由一起工作.
I'm currently learning Angular-CLI for a Project. I succeeded in creating a simple little project with some routing Objects. In dev mode with ng serve, everthing works just fine. I can call the localhost:port in the browser and it works with the routing.
.
在成功 ng build -prod 并将所有内容从 dist 目录移动到我的服务器文件夹 (Apache24/htdocs) 后,我启动了我的服务器并且主端 (mywebside) 工作正常,但是路由没有......(即本地主机/关于),而是我得到一个标准的错误页面,如下所示:
After a successful ng build -prod and moving all the stuff from the dist directory into my Server Folder (Apache24/htdocs), I start my Server and the main Side (mywebside) just works fine, the routing however does not... (i.e. localhost/about), instead I get a standart Error-Page as shown below:
希望我能够清楚地描述我做了什么以及我的问题在哪里.我没有发布任何代码,因为我认为问题出在其他地方.
Hope I was able to describe clearly what I did and where my problems are. I didn't posted any Code because I think the problem has to be else where.
感谢您的帮助!
曼努埃尔
angular CLI:Beta.8(最新)
angular CLI: Beta.8 (latest)
(apache):2.4.20
OK 搞定了(在 PierreDuc 的帮助下!)
OK figured it out (with help from PierreDuc!)
你必须做两件事:
- 在保存 index.html 文件的文件夹中添加一个 .htaccess 文件:(就像没有文件名一样!),插入以下代码:
- add a .htaccess file: (just like that no filename!) in the folder where your index.html File is saved, insert this code:
ErrorDocument 404/index.html
- 编辑 httpd.conf:
(在 Apache24/conf/目录中找到 File)搜索该行:
(you find the File in the Apache24/conf/ directory) search for the line:
[...]
-> 在我的 apache 版本中,它在第 244 行
<Directory "c:/Apache24/htdocs"> [...]
-> in my Version of apache it is in line 244
再往前几行(在几条评论之后)你应该找到这一行:
a few lines further (after a few comments) you should find this line:
AllowOverride none
-> 在我的 apache 版本中,它在第 264 行
AllowOverride none
-> in my Version of apache it is in line 264
将此行更改为
AllowOverride ALL
就是这样,现在您的 Angular-CLI 网站应该可以使用路由对象在生产版本中工作
Thats it, now your Angular-CLI Website should work in the production build with routing objects
希望对其他开发者有所帮助!
hope it might be helpful to other Developpers!
感谢 PierreDuc!
Thanks to PierreDuc!
曼努埃尔