Use the following guide to deploy your React portfolio to the root folder, public_html, folder on your server.
If you have a "homepage" key, set its value to "/".
"homepage": "/"
If you have a basename attribute in <BrowserRouter>
, set the value to "/".
<BrowserRouter basename="/">
In the defineConfig object, set the value of base to '/'.
base: '/'
In the public folder, create a file called .htaccess. Add the following code to allow your app to refresh without errors:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Run the following command:
npm run build
Upload the contents of the "dist" folder to the root folder on your server, public_html. Open your domain in a browser to check that the app loads properly.