I am building an application with the help of Angular6 and having problem in routing. All the routes are working when I click on a particular tab but whenever I refresh the current page, it is throwing 404 error. I tried Hashtag location strategy but getting # in URl. Is there any other way to implement without hash strategy. Currently application is hosted in AWS.
Asked
Active
Viewed 2,987 times
2
-
Possible duplicate of [Angular 2: 404 error occur when I refresh through the browser](https://stackoverflow.com/questions/35284988/angular-2-404-error-occur-when-i-refresh-through-the-browser) – Capricorn Aug 02 '18 at 15:04
2 Answers
2
one work around is adding index.html in error document section but it isn't recommended.
check other solutions here.

Abdul Rafay
- 3,241
- 4
- 25
- 50
-
Yep, the only solution I figured out is this one, adding index.html in the error document, cause angular router needs to resolve any route to return to the index.html, see this post https://stackoverflow.com/questions/35284988/angular-2-404-error-occur-when-i-refresh-through-the-browser – Sid Ali Aug 02 '18 at 17:49
0
Take a look at the Deployment section in the docs if you are using EC2. The webserver you are using must handle those requests:
If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have. A routed application should support "deep links". A deep link is a URL that specifies a path to a component inside the app. For example, http://someurl/heroes/42 is a deep link to the hero detail page that displays the hero with id: 42.
Are you using any webserver such as Apache or Nginx?

Christian Benseler
- 7,907
- 8
- 40
- 71
-
-
And how are you serving the application? What service are you using? – Christian Benseler Aug 02 '18 at 14:50
-
-
AWS has innumerous services and many of them can be used to serve static html applications (EC2, S3, etc). You should tell us which u are using. – Christian Benseler Aug 02 '18 at 17:03
-