reactjs - React app only show home page on the server
问题描述
i created a react app using create-react-app , after finishing the development i runned ' yarn build ' then i uploaded the files in the build folder on the server using fileZilla ( i have a premium account on hostinger ) in my package.json i added the following line :
"homepage": "https://goinprod.com/",
my .htaccess file located in the public_html folder looks like this :
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?goinprod.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW UPGRADE_INSECURE_REQUESTS:goinprod.com
Header always set Content-Security-Policy: upgrade-insecure-requests
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW UPGRADE_INSECURE_REQUESTS:goinprod.com
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?goinprod.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
the home page looks fine but when i navigate in another page it show the following error
file structure on the server :
static ( folder )
asset-manifest.json
favicon.ico
index.html
logo.png
logo2.png
manifest.json
.htaccess.
precache-manifest.json
robots.txt
service-worker.js
my website link : https://goinprod.com/
解决方案
这是一个路由问题,我刚刚在 public_html 文件夹的 .htaccess 文件中添加了以下代码:
<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>
推荐阅读
- networking - Game Maker Studio 网络客户端到服务器通信
- javascript - 从 API 响应中将带有引号的字符串作为参数传递给 JS 中的函数
- sql - 选择常量作为伪列并对伪列进行算术运算
- omnet++ - 当移动 UE 增加距离时,吞吐量的变化是不合逻辑的
- ms-access - Microsoft ACCESS doesn´t show photo in form
- c++ - 利用具有文件输入/输出和函数c ++的数组
- java - Java游戏:根据玩家的位置限制棋盘的可见性
- javascript - 在 VRView for web 中禁用陀螺仪/设备方向读取
- javascript - 节点奇怪的用户输入异步行为
- reactjs - Memoize 和 lodash 时间获取索引,创建唯一的文本输入