How to host a ReactJS project on a static server

2019-08-15 06:53发布

I have a built a React application and it runs fine from the local server. However, when I run npm run build, the process appears to execute correctly (creates build folder, which contains the bundled js file and the index.html file), but when I open index.html in my browser it renders nothing. I read something about static server to use node.js, the problem is, Im paying hostgator and to use a static server I need to pay for month almost the amount that Im paying for year, there is some way to run it on a server without node, apache etc? (because the project is already done)... Thanks guys appreciate!

1条回答
贼婆χ
2楼-- · 2019-08-15 07:21

On the place you are putting your build file (screenshot at last)

You need to create .htacces file

Copy and paste this content in that .htacces

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

It should probably work now.

[Note:] Try creating it using file option in your Cpanel and once it is created, edit .htacess file and paste the above code snippet (3rd and 4th Image).

Something like this

enter image description here

Where .htacess file looks like this enter image description here

adding new file enter image description here

Click on .htacess file and then select edit to edit it enter image description here

查看更多
登录 后发表回答