title: How to configure asp.net core to return react front end and work with react-router?
body: <p>I would like my backend to serve up my front end (which is written in react). I added the following cade to <code>program.cs</code>:</p>
  <pre><code>var frontEndBuildDirectory = &quot;Path to front end build directory&quot;;
  app.UseFileServer(new FileServerOptions()
  {
      FileProvider = new PhysicalFileProvider(frontEndBuildDirectory ),
      RequestPath = &quot;&quot;
  });
  </code></pre>
  <p>My understanding is that this code does two things:</p>
  <ol>
  <li>If a request's url starts with the host name of my backend (<code>localhost:xyzw</code>), everything following the host name will be a virtual path into <code>frontEndBuildDirectory</code>.</li>
  <li>When a request is made into <code>frontEndBuildDirectory</code> (the directory itself, not a file within the directory), then the response is the <code>index.html</code> file within <code>frontEndBuildDirectory</code>.</li>
  </ol>
  <p>The problem is that my react code uses the react-router library. If I make a request to the backend (<code>localhost:xyzw</code>), the front end is served. Then when I click on something that changes the route (using react router), the url changes to <code>localhost:xyzw/route1</code> and the everything works. However, if I try to search up <code>localhost:xyzw/route1</code>, I get a page not found error.</p>
  <p>My understanding is that this happens because there is no file named <code>route1</code> in <code>frontEndBuildDirectory</code>.</p>
  <p>What is the proper way to make requests like <code>localhost:xyzw/route1</code> not give a page not found error?</p>