Serve create-react-app from a subdirectory
If you've tried to deploy create-react-app to a non-root subdirectory (i.e. example.com/app/), then you'll need the following to make it work:
Sources:
- Set the homepage in project.json
- "homepage": "https://example.com/app/"
- If you are using Router:
- Set the basename attribute:
- <Router basename={'/app'}>
- Set Route path prefixes
- <Route path={`${process.env.PUBLIC_URL}/dashboard`} component={Dashboard} />
- Update Link tags
- <Link to={`${process.env.PUBLIC_URL}/dashboard`}>
Sources: