'File download failed in ReactJS
I am trying to download file from src folder in my react app, but file download is failing
file import
import test from "../../test.json";
download
const link = document.createElement("a");
link.href = test;
link.setAttribute("download", `test.json`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
Solution 1:[1]
You can not download files in the src folder. If you need this file and change it in every build, you can use a script and run it before building for copying files from src to the public folder. If not, you must copy the file to the public folder.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Iman Rabbi |

