M
M
Mikhail Plyusnin2016-11-29 16:34:14
IIS
Mikhail Plyusnin, 2016-11-29 16:34:14

Page reload results in 404 error (React Router)?

Good evening, the bottom line is that locally the application (front - Reactjs + Redux, back - webApi.Net) works fine, using express + hot. Everything loads, opens, runs through the links, press f5, the page (let's say /organization) reloads and starts from the same url on which it was, in general, everything works, nothing falls.
We decided to put this whole thing on a combat server (IIS) today, everything works, but wait, when I press f5 and reload the page (let's say /organization) it falls into a 404 error and in order to start working with the application again, I need to go to the initial url ('/'), in general, somehow uncomfortable, although locally it would reboot and not fall. I'm using react-route with browserHistory, maybe that's the issue? Who has overcome this problem? Or is this behavior expected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-11-29
@rpe4a

All requests should be directed to the main page.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="All" patternSyntax="Wildcard" stopProcessing="true" enabled="true">
        <match url="*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" 
               matchType="IsFile" 
               negate="true" 
               pattern="" 
               ignoreCase="false" 
          />
        </conditions>
        <action type="Rewrite" url="index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

After making changes, don't forget to restart the worker process (pool).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question