简体   繁体   English

React:如何在没有 PUBLIC_URL 出现在路由中的情况下提供资产?

[英]React: How can I serve assets without the PUBLIC_URL appearing in the route?

I have a portfolio website which contains my resume.我有一个包含我的简历的投资组合网站。 I want the route http://localhost:3000/resume.pdf to open my resume for people to see.我希望路线http://localhost:3000/resume.pdf打开我的简历供人们查看。 The resume.pdf file is inside my public folder. resume.pdf 文件位于我的公共文件夹中。 Unfortunately, this does not work and I have to go to http://localhost:3000/personal-website/resume.pdf to actually see my resume.不幸的是,这不起作用,我必须 go 到http://localhost:3000/personal-website/resume.pdf才能真正看到我的简历。 How can I get rid of the /personal-website prefix caused by the process.env.PUBLIC_URL?如何摆脱由 process.env.PUBLIC_URL 引起的/personal-website前缀?

My code looks like this <href={process.env.PUBLIC_URL + "/resume.pdf"}> Resume </a>我的代码看起来像这样<href={process.env.PUBLIC_URL + "/resume.pdf"}> Resume </a>

If you are running apache server, you can use .htaccess如果您正在运行 apache 服务器,您可以使用.htaccess

RewriteEngine on
RewriteRule ^resume.pdf personal-website/resume.pdf [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM