download sample file in public folder (react)

人走茶凉 提交于 2020-07-31 04:36:08

问题


I want to put a sample xlsx file in my public folder (react project) and others can download this file.

<Button><link rel="chargeSample" href="%PUBLIC_URL%/chargeSample.xlsx"></link></Button>

How can I do this?


回答1:


The tag defines a link between a document and an external resource. To let download funcionality on your website you should change link tag

import chargeSample from './public/chargeSample.xlsx';

<Button><a href={chargeSample} download="your file name">Download</a></Button>



回答2:


If you are using creat react app, you can pass public path into your components at build time by using

process.env.PUBLIC_URL


来源:https://stackoverflow.com/questions/57374561/download-sample-file-in-public-folder-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!