Angular CLI路由-在(Apache-)服务器上不起作用 [英] Angular CLI routing - Doesn't work on (Apache-) Server

查看:114
本文介绍了Angular CLI路由-在(Apache-)服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为一个项目学习Angular-CLI.我成功创建了一个带有路由对象的简单小项目.在具有 ng服务的开发人员模式下,一切正常.我可以在浏览器中调用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)正常运行,但是路由却没有...(即localhost/about),而是出现如下所示的标准错误页面:

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.

谢谢您的帮助!

Manuel

角度CLI :Beta.8(最新)

angular CLI: Beta.8 (latest)

(apache):2.4.20

推荐答案

确定(在PierreDuc的帮助下)!

OK figured it out (with help from PierreDuc!)

您必须做两件事:

  1. 在保存index.html文件的文件夹中添加.htaccess文件:(就像没有文件名一样!),插入以下代码:
  1. 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

  1. 编辑httpd.conf:

(您在Apache24/conf/目录中找到文件)搜索以下行:

(you find the File in the Apache24/conf/ directory) search for the line:

<Directory "c:/Apache24/htdocs"> [...]->在我的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!

Manuel

这篇关于Angular CLI路由-在(Apache-)服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆