Many times You need to download File from your react js app So in this tutorial we are going to learn How to Download File in React js? Let’s start this tutorial without wasting your time.
How to Download File in React js?
- How to Download File in React js?
To Download File in React js It is simple to download file in React app just use the anchor tag in your react app just like this: <a href=’../path/to/file.txt’ download>Click Here to download</a> And this is how you can download file in react js app. Thanks.
- Download File in React js
To Download File in React js In React Router You can Use a Link tag. First of all, Put Your_file.txt into the public folder and Then use Link Just like this: <Link to=”/your_file.txt” target=”_blank” download>Download</Link> Now, You can download file. Thank You.
Method 1: Use Anchor Tag
It is simple to download file in React app just use the anchor tag in your react app just like this.
import myTxtFile from '../path/to/file.txt';
<a href={myTxtFile} download>Click Here to download</a>
And this is how you can download file. Thanks.
Method 2: Use Link Tag
In React Router You can Use a Link tag. First of all, Put Your_file.txt into the public folder and Then use Link Just like this.
<Link to="/your_file.txt" target="_blank" download>Download</Link>
Now, You can download file. Thank You.
Conclusion
It’s all About this article. Hope this method worked for you. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read
- How to Use .env File in React Project?
- Attempted import error: ‘Redirect’ is not exported from ‘react-router-dom’
- Attempted import error: ‘useHistory’ is not exported from ‘react-router-dom’
- Module not found: Can’t resolve ‘web-vitals’
- Module not found: Can’t resolve ‘@mui/icons-material/FileDownload’