image/file 上传后防止在 create-react-app 中重新加载页面

Prevent page reload in create-react-app after image/file upload

我正在从 'src' 文件夹中的文件夹中获取图像(应用程序是使用 'create-react-app' 创建的)。

我有表格,提交后会上传一张新图片到文件夹 'client/src/images'。之后该页面会自动重新加载。我有带有用户模型的数据库,这个模型有字符串格式的图像。因此,在提交表单后,会创建一个新图像并将其推送到 '/images' 文件夹中,这会导致页面重新加载。我需要阻止这种情况。如何禁用对观看此特定文件夹的反应?或者作为替代方案,我想在 src 目录之外加载图像。找到了react-app-rewired,但是真的没看懂。

我会感谢你的answer/advice!

这样做,好的,所以你想要做的是从按钮中删除提交类型 <input type="button" value="Basic file Upload"> 或在 onClick 事件而不是 submit 上调用您的 imageUplaod 函数。
可以转成web pack,可以忽略images文件夹:

module.exports = {   
devServer: {     
   watchOptions: {
      ignored: [ path.resolve(__dirname, 'dist'),         
                 path.resolve(__dirname, 'node_modules'),         
                 path.resolve(__dirname, 'images') // image folder path 
                ]    
}},}