I'm using Angular 8 in my single page application project. When I upload my published code in IIS server and I don't use hash(#) in routing, It will get 404 error while I'm refreshing the page. Please help me out for this. Is there any solution to remove this error without using hash(#) in routing? because I want to make my URL SEO friendly.
Asked
Active
Viewed 2,396 times
1
-
You should add rewrite rules to `web.config` file, refer this https://stackoverflow.com/questions/43785928/angular-2-hosted-on-iis-http-error-404 – hrdkisback Sep 27 '19 at 05:48
-
I added these rules in my web.config file but it didn't remove the hash(#)
– Pritee Mehta Sep 27 '19 at 06:58 -
If you want to deploy just an angular app, you can simple create an express app and serve angular dist to it. Express will take care of routing, you won't get 404. – Sathwik Gangisetty Sep 27 '19 at 07:01
-
thanks but I didn't get what exactly you are saying. can you please explain me how to create express app for angular ? – Pritee Mehta Sep 27 '19 at 07:05
-
For remove (#) from url you have to use `RouterModule.forRoot(routes, { useHash: false })` in `app.module.ts` file under `imports` section. Also refer this one https://stackoverflow.com/questions/53612218/angular-app-url-always-saying-404-on-refresh-after-deploy-on-iis – hrdkisback Sep 27 '19 at 07:23
-
@hrdkisback - Thanks. I set useHash: false in appModule.ts file and also changed route in web.config file but still I get an error of 404. – Pritee Mehta Sep 27 '19 at 07:38
-
Can you provide `URL` of application? – hrdkisback Sep 27 '19 at 08:55
1 Answers
0
You are getting a 404 because there is no HTML in path you have requested on your hosting server. It is needed for SPA to set up a redirection to index.html. Angular then will bootstrap application and redirect to proper view.
This is how to set it up in the most common web servers.

karoluS
- 2,980
- 2
- 23
- 44
-
I added these rules in my web.config file but it didn't remove the hash(#)
– Pritee Mehta Sep 27 '19 at 06:56