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:


  1. Set the homepage in project.json
    • "homepage": "https://example.com/app/"
  2. 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:

Popular posts from this blog

Google sign-in with pwa_auth

Components in React: "class" and "functional"