首页 > 解决方案 > 有没有办法在 React 中访问根目录之外的图像

问题描述

想法是使用 Express 将图像上传到 React 根文件夹之外的文件夹中,然后使用数据库中的图像名称,从文件夹中获取图像文件。

在此处输入图像描述

app.use(express.static(path.join(__dirname, "client/build")));

app.get("*", (req, res) => {
    res.sendFile(path.join(__dirname, "client", "build", "index.html"))
})

标签: node.jsreactjsexpress

解决方案


推荐阅读