I am trying to deploy my react app in azure websites. I have successfully done it. Since it is a single page application, it does not work on reloads. During the reloads, 404 error status code is displayed.
I want to redirect the page to / (index.html or root) on occurrence of 404. I am able to do it by editing the web.config file. But I cant find out the specific redirection policy that i need. For eg:
I need to redirect:
http://letsmeetupp.azurewebsites.net/event/eventId=dsdsd-dsdsd-1475750226814
this to
http://letsmeetupp.azurewebsites.net/#!/event/eventId=dsdsd-dsdsd-1475750226814
I want to redirect with the prefix #!/, so that I can find that path in my react app and push states in html 5.
My current web.config file is this. This gets me redirected to /, but I need the whole path with the prefix, which help me to parse the hash and push states (HTML 5 HISTORY API).
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
<customErrors mode="On">
<error statusCode="404" redirect="index.aspx?sec=404" />
</customErrors>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
<httpErrors errorMode="Custom" existingResponse="PassThrough">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="#!/" path="/" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
Edit after jambor Comments:
Hey @Jambor-MSFT. I have a reactJS (single page application) deployed on azure websites. The thing is my SPA is an MVC. I have defined my routes there. Technically, I am using react-router to define the routes in my SPA app. So to your question Does it works fine on your local ?. Yes indeed. I understand that IIS cant understand the routes. I mean it renders index.html when http://letsmeetupp.azurewebsites.net hits the browser. And all the routes are internally managed by react file that is included in index.html. What I want is on different routes other than /, it should redirect to index.html with a prefix. like this http://letsmeetupp.azurewebsites.net/#!/event/eventId=dsdsd. After this, I can internally handle the routes by removing the prefix and rendering the correct path.