Angular CLI routing - not working on server (Apache-)

I am currently studying Angular -CLI for a project. I managed to create a simple small project with some routing objects. In dev mode with ng serve, everything works fine. I can call localhost: port in the browser and works with routing.

Routing on execution using ng server .

After successfully ng build -prod and moving all the material from the dist directory to my server folder (Apache24 / htdocs), I start my server and the main side (mywebside) works fine, but the routing doesn’t ... (i.e. localhost / about ), instead, I get a standard error page, as shown below:

Missing page error

I hope I could clearly describe what I did and where my problems are. I have not posted any code because I think the problem should be in a different place.

Thank you for your help!

Manuel

Version:

angular CLI : Beta 8. (latest)

(apache) : 2.4.20

+6
source share
1 answer

OK figured it out (using PierreDuc!)

You need to do 2 things:

  • add the .htaccess file: (as well as the file name!) in the folder where your index.html file is stored, paste this code:

ErrorDocument 404 /index.html

  1. Edit httpd.conf:

(you will find the file in the Apache24 / conf / directory), find the line:

<Directory "c:/Apache24/htdocs"> [...] β†’ in my version apache is on line 244

a few lines (after a few comments) you should find this line:

AllowOverride none in my apache version is on line 264

change this line to

AllowOverride ALL

So, now your Angular-CLI site should work in assembly with routing objects

Hope this can be useful to other developers!

Thanks PierreDuc!

Manuel

+7
source

All Articles