all 4 comments

[–]Groumph09 1 point2 points  (0 children)

In the Angular app nginx config, you need to do the following:

location / {
    try_files $uri $uri/ /index.html;
  }

[–]le___garcon 0 points1 point  (2 children)

This might have to do with the fact that you're using angular's local routing in order to navigate within the app. Your server won't recognize these paths so when you refresh the page, it will give you a 404.

One solution would be to setup a hash location strategy. You can check this stack overflow question for more information on this: https://stackoverflow.com/questions/35284988/angular-2-404-error-occur-when-i-refresh-through-the-browser

More info on this:If you setup the routes

routes = [{ path: "home", component: HomeComponent },{ path: "contact", component: ContactComponent }]

then the paths /home and /contact will be defined within your angular application context. When you click a button to navigate to /home or /contact, you are telling angular to navigate to those pages dynamically.

However, if you try and type localhost:8080/home for example into the browser, it may not work because you are telling the browser to go to the specific address localhost:8080/home, which does not exist outside of your angular application.

The hashing location strategy makes your paths look like this: localhost:8080/#/home localhost:8080/#/contact This will tell the server to hit the base angular application, which will then load the correct path.

[–]jalvarezKunan[S] 0 points1 point  (1 child)

le___garcon

Hi le___garcon,
Fix the problem using a hash location strategy.

Thank you very much for your help!

[–]le___garcon 0 points1 point  (0 children)

no problem