Raj thapa
Raj thapa

Reputation: 1

Why is the download button using anchor tag in react js not working?

hello i want to create a download button in react js, so that user can download a pdf file by clicking that button. i used the anchor tag with download attribute but it is not working. when i click the download button, it says "failed no file" in the small pop up window.

<a href="./test.pdf" download> Download </a>

The pdf file is in the src folder.

Upvotes: 0

Views: 782

Answers (1)

iamziike
iamziike

Reputation: 1109

inside the file that has

<a href="./test.pdf" download> Download </a>

do this rather

import testPDF from './test.pdf';
<a href={testPDF} download> Download </a>

this solution will work, assuming both the pdf and the jsx file are within the same directory "./src"

Upvotes: 1

Related Questions