title: Routing problem when building "react js" to wwwroot folder of my "asp.net core web api"
body: <p><strong>Application information</strong></p>
  
  <p>My application uses asp.net core web API for the server-side and React js for the client-side.</p>
  
  <p>Before publishing the application, the react js code is built straight to the www root folder of my asp.net Core web API. This allows the hosting of the client and the API on the same URL.</p>
  
  <p>My client uses is a SPA and makes use of react routing. When starting at "localhost:44362/" my asp.net core application redirects the user to the index.html file in my www-root folder.</p>
  
  <p>When this happens the client starts using the react-router package.</p>
  
  <p><strong>The problem</strong></p>
  
  <p>let's say that our current location is "localhost:44362/dashboard"
  When we refresh the page we don't go directly through the react routing but first the asp.net core routing. This will result in a 404 page because the actual routing can not be found by the server.</p>
  
  <p>What actually should happen is that on refresh the page should go through the index.html and after execute the /dashboard request.</p>
  
  <p><strong>What I have tried</strong></p>
  
  <p>I have tried altering the web.config file in replacing the http error status code 404 behavior to change the executionURL to /index.html as displayed below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.webServer&gt;
      &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
        &lt;remove statusCode="404" /&gt;
        &lt;error statusCode="404" responseMode="ExecuteURL" path="/index.html" /&gt;
      &lt;/httpErrors&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Note: When changing the existingResponse="Replace" part to something else, this solution breaks.</p>
  
  <p><strong>This works for refreshing but breaks the regular error responses</strong></p>
  
  <p>When referring to this solution, the regular HTTP response will all be replaced.</p>
  
  <p>example:</p>
  
  <ul>
  <li>A user fills in the wrong password and submits a login request</li>
  <li>The server sends a 400 HTTP error response with the body "incorrect password"</li>
  <li>The error response body is replaced by the web.config</li>
  <li>The server now only sends back "bad request" instead of "incorrect password"</li>
  </ul>
  
  <p><strong>My question</strong></p>
  
  <p>Is there any way to make the routing work while still keeping the right error response messages?</p>