Home > OS >  Download a file which is saved in your project - javascript react
Download a file which is saved in your project - javascript react

Time:10-06

I am working on a react project using typescript. I have an excel file (.xlsx) in a folder in my project. My task is to create a button or a link on the UI and when clicked on this UI, download the file which is stored in my project folder. I looked up a bit online and found the <a> tag which has the href and the download attributes. But the href attribute is for links only.. How do we download an excel sheet or any file specified in a folder in our project?

Any help would be appreciated.

CodePudding user response:

You can pass relative path to href attribute of your a tag, something like this:

<a href="/files/my-fyle.xlsx" download>Download</a>

CodePudding user response:

If you are using react router .. try this

<Link to="/files/file.xlsx" target="_blank" download>Download</Link>
  • Related