如何在 create-react-app 项目中链接到本地​​ pdf 文件? [英] How do I link to local pdf file in a create-react-app project?

查看:36
本文介绍了如何在 create-react-app 项目中链接到本地​​ pdf 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 create-react-app 项目,我想在其中链接到我保存在项目中的 pdf 文件.我想我的问题是双重的:

I have a create-react-app project in which I want to link to a pdf file I have saved in my project. I suppose my questions are twofold:

1) 我不确定我需要在哪里保存 PDF 文件(src 文件夹与公共文件夹)

1) I'm not sure where exactly I need to save the PDF file (src folder vs public folder)

2) 如何正确链接到 pdf 文件?现在我有这样的事情:

2) How do I properly link to the pdf file? Right now I have something like this:

<a href="/portfolio-revamp/public/documents/resume.pdf">Resume</a>

它没有显示 - 它更改了 URL,但不会将您带到 PDF.

and it's not displaying - it changes the URL but doesn't take you to the PDF.

非常感谢任何建议!

推荐答案

您需要将文件放在公共文件夹中.如果您希望它在浏览器中打开,这就是它会做的.如果要强制用户下载,可以在锚标签中添加'download'属性.

You need to have the file in the public folder. If you want it to open in a browser, that's what it will do. If you want to force users to download, you can add the 'download' attribute to the anchor tag.

这篇关于如何在 create-react-app 项目中链接到本地​​ pdf 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆