reactjs - 可下载文件 - Gatsby

标签 reactjs gatsby

由于某种原因,尝试下载文件时失败。我尝试了几种不同的方法,但都失败了。比我读到一些关于 pdf/word 文件在 Gatsby 中被“禁止”的内容??!

默认<a href="route-to-file" download></a>好像没有用,显示下载失败。任何帮助表示赞赏!

最佳答案

Importing Assets Directly Into FilesUsing the Static Folder

import React from "react"
import downloadFile from '../downloads/file.pdf' 

  const IndexPage = () => (
  <>
    <a href={downloadFile} download>Download the directly imported file</a>{` `}
    <a href={`download.pdf`} download>Download the file that is already in your static folder</a>
  </>
)

export default IndexPage

关于reactjs - 可下载文件 - Gatsby ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57258465/

相关文章:

javascript - React-Native:如何从 React Native 应用程序打开 Google Play 商店?

reactjs - 具有内部隔离 Redux 存储的可重用组件

javascript - 如何根据 Redux 存储上的属性显示/隐藏组件?

javascript - 类型错误 : Cannot read property 'fluid' of null

javascript - React 中出现意外标记 '<'(HTML 文件)

javascript - 我需要正则表达式来屏蔽 javascript 中的电子邮件地址

javascript - 在页面级查询中使用页面的查询参数作为参数

Gatsby 动态样式在生产版本中不起作用

javascript - 为什么 `useContext` 不重新渲染我的组件?