Search code examples
reactjsapachenpmcreate-react-app

React: 404/No folder structure after running `npm run build`


I can access my index page perfectly with the following apache config

    <VirtualHost *:443>
        ServerName MyReactAppSite

        DocumentRoot /var/www/sites/MyReactAppSite/client/build/

    </VirtualHost>

in my App.js folder I have the following code

<Route exact path="/home" component={Home} />

So after logging in app routes to http://MyReactAppSite/home

Works perfectly with >> npm run start

404 not found >> npm run build followed by serve -s build

When I look inside the /build folder there is no /home folder so what is the proper way to get a production build of a React App. I have read this whole page 2x https://create-react-app.dev/docs/deployment/ and can't seem to figure it out.


Solution

  • In order to facilitate the REST attributes of my particular app I had to set up a .htaccess file to rout all request back into the index.html file created by my React App build.

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteCond %{REQUEST_URI} !=/upload
      RewriteCond %{REQUEST_URI} !=/tmp
      RewriteRule ^ index.html [L]
    </IfModule>