在React-Router 4中查看/下载Pdf文件 [英] View/Download Pdf Files in React - Router 4

查看:70
本文介绍了在React-Router 4中查看/下载Pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目的文件夹中有一组pdf文件。

I have a set of pdf files sitting in a folder in my project.

我要做的就是创建指向这些PDF文件的链接并查看它们在浏览器中或下载它。

All I need to do is to create a link to these PDF files and view them in browser or download it.

我使用React Router 4和React 16以及create-react-app自举工具。

I use React Router 4 and React 16 and create-react-app bootstrapping tool.

无论我如何链接(链接组件或标签),它仍然会到达路由器配置中的最后一条路由。

Regardless of how I link it (Link component or a tag) it still goes to my last Route in my router config.

我一直在搜索最后两个小时...但是没有运气。

I have been googling for last two hours... But no luck..

有没有办法告诉路由器不要为PDF / XLS文件路由?

Is there any way to tell router not to route for PDF/XLS files?

谢谢

推荐答案

我遇到了同样的问题,我认为这是因为CRA处理查询的方式:我结束了将我的PDF文件放在公用文件夹中,并使用以下链接:

I met the same issue, I think it's because of the way CRA handles queries : I ended up putting my PDF files in the public folder, and link to them using :

{process.env.PUBLIC_URL + '/myfile.pdf'}

作为我的代码的源代码。

as src to my tags.

我猜不是最好的方法,但是效果很好...

Not the best way I guess, but works fine enough...

这篇关于在React-Router 4中查看/下载Pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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