问题
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