【问题标题】:React app only show home page on the serverReact 应用程序仅在服务器上显示主页
【发布时间】:2020-11-29 05:19:36
【问题描述】:

我使用 create-react-app 创建了一个 react 应用程序,完成开发后我运行了“yarn build”,然后我使用 fileZilla 将文件上传到服务器上的 build 文件夹中(我在托管程序上有一个高级帐户) 在我的 package.json 中,我添加了以下行:

"homepage": "https://goinprod.com/",

我位于 public_html 文件夹中的 .htaccess 文件如下所示:

# 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

主页看起来不错,但是当我在另一个页面中导航时,它显示以下错误

服务器上的文件结构:

static ( folder )
asset-manifest.json
favicon.ico
index.html
logo.png
logo2.png
manifest.json
.htaccess.
precache-manifest.json
robots.txt
service-worker.js

我的网站链接:https://goinprod.com/

【问题讨论】:

  • 你能显示你的文件结构吗?你在使用客户端路由吗?也许您可以提供更多上下文
  • 我添加了文件结构!是的,我用户反应路由器

标签: reactjs .htaccess web-deployment create-react-app host


【解决方案1】:

这是一个路由问题,我刚刚在 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>

【讨论】:

    猜你喜欢
    • 2015-08-04
    • 2020-10-04
    • 2020-10-26
    • 2021-07-22
    • 2019-03-10
    • 2014-09-04
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多