Create-React-App公用文件夹子文件夹

问题描述 投票:1回答:1

我在公用文件夹中有一些子文件夹。当我构建这些子文件夹时,将其放在构建文件夹的根目录中。

public/
  mySubfolder/
  favicon.ico
  index.html
  ...

build/
  mySubfolder/ 
  static/
  favicon.ico
  index.html
  ...

当我使用express,serve或firebase,heroku将这些文件作为静态提供时,现在......我无法通过url访问这些子文件夹。示例:如果我将其中一个子文件夹中的一个文件放在iframe中,我无法访问它,而如果我将路径放在img标签的src属性中则可以工作..也许子文件夹与路径冲突,但我没有带有子文件夹名称的路由。

我的项目是在github:https://github.com/Darklod/p5-sketches-react/tree/heroku?files=1

附:我已经阅读了本指南:https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment

reactjs static create-react-app static-files public-folders
1个回答
0
投票

要使用Express提供React应用程序,您需要在配置中使用以下内容:

app.use(express.static(path.join(__dirname, 'react')));

app.get('*', (req, res) => {
     res.sendFile(path.join(path.join(__dirname, 'react/index.html'));
});

在该示例中,将react替换为您的React应用程序所在的文件夹

我遗憾的是还没有使用firebase或heroku来提供React应用程序,所以我很遗憾无法帮助你解决这个问题,但我希望Express部分能够解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.