Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular CLI routing - Doesn't work on (Apache-) Server

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.

Routing when executed with ng server.

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:

Missing Page Error

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.

Thank you for your help!

Manuel

Versions:

angular CLI: Beta.8 (latest)

(apache): 2.4.20

like image 811
Manuel Avatar asked Jul 04 '16 11:07

Manuel


1 Answers

OK figured it out (with help from PierreDuc!)

You have to do 2 things:

  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. Edit the httpd.conf:

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

<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 -> in my Version of apache it is in line 264

change this line to

AllowOverride ALL

Thats it, now your Angular-CLI Website should work in the production build with routing objects

hope it might be helpful to other Developpers!

Thanks to PierreDuc!

Manuel

like image 187
Manuel Avatar answered Oct 20 '22 00:10

Manuel