0

I have a multipage React App that I have used the create-react-app tool to make, however it's come to the point where I need to deploy it. The issue I am having is that the Router doesn't seem to work properly when I upload to cPanal, for example /Library will throw a 404, when locally it will just serve the /Library page.

Does anyone have any experience with deploying multipage apps with React to cPanal?

Ash._
  • 364
  • 1
  • 3
  • 16
  • You will need to configure the server to serve your react app main file on any request. Unfortunately, I don't have the experience with doing it in cPanel. – Gleb Kostyunin Jan 17 '18 at 13:56

2 Answers2

0

This has actually been answered here.

cPanal has a .htaccess file but it's hidden. It just needs opening up and editing to include the code from the answer to the question below.

Apache web server doesn't allow me to refresh on /about but on localhost its working fine

Ash._
  • 364
  • 1
  • 3
  • 16
0

you need .htaccess file in your public directory.

First make sure that .htaccess file is in your document root (the same place as index.html) or it'll only affect the sub-folder it's in (and any sub-folders within that - recursively).

Simplest example of .htaccess file to achive what you want. Create .htaccess file in your public directory and put below code in that

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

what it does ? it simply loads the index.html on every request. eg. if you hits /Library in a browser it loads the index.html in which your react app is instantiate.

Prakash Naidu
  • 742
  • 2
  • 7
  • 17