title: React Router with relative path deployment
body: <p>My question is concerning the <code>react-router-dom</code> in conjunction with deployment to a relative path (see <a href="https://create-react-app.dev/docs/deployment#building-for-relative-paths" rel="noreferrer">https://create-react-app.dev/docs/deployment#building-for-relative-paths</a>). On my dev environment the router is working fine, but once i build and deploy my application with the <code>homepage</code> tag set in <code>package.json</code> the router does not seem to work anymore. </p>
  
  <p>First of all i would assume that it would be working. After all it's a build option by react to make a build for a specific url and i would assume the same functionality with that relative path in place. However neither the <code>&lt;Link to=""&gt;</code> parts nor the <code>&lt;Switch&gt;</code> do respect the relative path of my react app.</p>
  
  <p>Second of all i have not found a solution to circumvent this behavior. Any ideas?</p>
  
  <p>Other question dealing with react router and relative paths are focusing on a totally different topic. So i have not found an answer to my question. This <a href="https://stackoverflow.com/questions/50250223/react-router-app-deployed-on-different-locations-subdirectories">React-router app deployed on different locations (subdirectories)</a> is maybe getting close and could be a way to deal with that.</p>
  
  <p>For info:</p>
  
  <pre><code>"react-dom": "^16.8.6",
  "react-router-dom": "^5.0.1",
  </code></pre>
  
  <p><strong>EDIT and PS:</strong></p>
  
  <p>I would probably just need to set a basename. If the basename is changing i would at least want to infer it from the setting in the <code>package.json</code> and not change my code depending on some <code>package.json</code> setting.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p><em>I could use <code>basename={process.env.PUBLIC_URL}</code> to set the basename to the correct URL. However the routes are still not matching. The links however appear to be fine, so <code>&lt;Link to="/xx"&gt;</code> would actually result in an link to <code>{process.env.PUBLIC_URL}/xx</code> which is the desired behavior, but the routers <code>&lt;Switch&gt;</code> does not match them.</em> <strong>Actually this is the answer and you can scratch that.</strong> </p>
  
  <p>Using <code>basename={process.env.PUBLIC_URL}</code> does solve my problem.</p>