View/Download Pdf Files in React - Router 4
·
Answer a question
I have a set of pdf files sitting in a folder in my project.
All I need to do is to create a link to these PDF files and view them in browser or download it.
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..
Is there any way to tell router not to route for PDF/XLS files?
Thanks
Answers
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...
更多推荐
所有评论(0)