【问题标题】:React: 404/No folder structure after running `npm run build`反应:404/运行`npm run build`后没有文件夹结构
【发布时间】:2020-06-15 07:15:30
【问题描述】:

我可以使用以下 apache 配置完美访问我的索引页面

    <VirtualHost *:443>
        ServerName MyReactAppSite

        DocumentRoot /var/www/sites/MyReactAppSite/client/build/

    </VirtualHost>

在我的 App.js 文件夹中,我有以下代码

<Route exact path="/home" component={Home} />

所以登录后应用路由到http://MyReactAppSite/home

完美搭配 >> npm run start

404 未找到 >> npm run build 后跟 serve -s build

当我查看 /build 文件夹时,没有 /home 文件夹,那么获取 React 应用程序的生产构建的正确方法是什么。我已经阅读了整页 2x https://create-react-app.dev/docs/deployment/ 并且似乎无法弄清楚。

【问题讨论】:

    标签: reactjs apache npm create-react-app


    【解决方案1】:

    为了方便我的特定应用程序的 REST 属性,我必须设置一个 .htaccess 文件来将所有请求路由回我的 React 应用程序构建创建的 index.html 文件中。

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteCond %{REQUEST_URI} !=/upload
      RewriteCond %{REQUEST_URI} !=/tmp
      RewriteRule ^ index.html [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 2021-03-04
      • 2021-03-03
      • 2021-03-26
      • 1970-01-01
      • 2020-12-16
      • 2020-09-17
      • 2021-02-18
      • 2020-03-21
      相关资源
      最近更新 更多