Home > Software design >  How to link downloadable files in docusaurus?
How to link downloadable files in docusaurus?

Time:03-09

I want to link downloadable content on my documentation.

I tried putting in a link like this:

<a
  href={
    require("@site/static/img/04-api/01/API-Description.png")
      .default
  } download="file-name"
>  download </a>

This generates following html:

download

<a download="file-name" href="/assets/images/API-Description-6aeb65d8ae136a70b1b5a3d916d27ca0.png">  download </a>

When I click on the link:

I get "Page Not Found"

Edit:

I am running version: 2.0.0-beta.17

Solved:

You have to use inline-html with the download attribute and target="_blank"

[not working](/logo.png)

<a href={ require("/logo.png").default } download={"origName"}>not working</a>

<a target="_blank" href={ require("/logo.png").default } download>working</a>

CodePudding user response:

I found two of doing this.

First, put the file inside the static folder.
Example: ./static/image.png.

1) Your way

<a href={ require("/image.png").default }>download</a>

2) Simple way

[download](/image.png)

** Note that we did not use the ! to indicate that is an image.

  • Related