How to bundle a React app to a subdirectory on a server?

If you are using React Router v4 you should be able to set it using basename={foobar}.

<Router history={browserHistory} basename={'foobar'}>
  <Route path="https://stackoverflow.com/" component={App} />
</Router>

Link to the docs: https://reacttraining.com/react-router/web/api/BrowserRouter

Note: if using create-react-app in a sub directory you will also want to set "homepage": "/foobar/", in your package.json file. So the production build points at the right path.

Leave a Comment