title: Get React root url path
body: <p>I'm creating a react app with create-react-app and react-router.
  I would like to get the root URL path of my react app as it can be served in a different location :</p>
  
  <ul>
  <li>In production: example.com/interface/</li>
  <li>In local: localhost/</li>
  </ul>
  
  <p>The links to the different pages are not affected by this difference because react-router handle to-location according to the react root path.
  Actually, my images are stored in the public path, therefore, I can access it in the base locations: <code>/&lt;page&gt;</code></p>
  
  <pre><code>&lt;img src={images/example.png}&gt;
  </code></pre>
  
  <p>but if I'm in a subpage or just if the URL ended with a "/" like <code>/&lt;page&gt;/</code> </p>
  
  <pre><code>&lt;img src={images/example.png}&gt;
  </code></pre>
  
  <p>won't work because browser searches the image at <code>/&lt;page&gt;/images/example.png</code> instead of <code>/images/example.png</code>.
  Moreover, if I set the image src to <code>/images/example.png</code> It works only on localhost but not in production because in production, browser searches the image at <code>example.com/images/example.png</code> instead of <code>example.com/interface/images/example.png</code></p>
  
  <p>That's why I need to get the react root URL path. It allows me to get "/" in localhost and "/interface/" in production for example</p>
  
  <p>Thank you for helping</p>