[英]Images not displayed on gh-pages after deploying react app
我创建了一个应用程序,其中我给出了社区推荐的图像路径。 在本地运行时,它会加载并显示所有图像,但是当我在github页面上部署后,它并没有采用正确的路径来获取图像。 我不知道如何解决该问题,有人可以帮助我吗?
我已尝试添加%PUBLIC_URL%,但所有内容似乎均不起作用
这就是我尝试过并在本地工作的方式。 我的图片位于
public/images/login-background.png
background: url('/images/login-background.jpg') center center
no-repeat;
当我将项目发布到github时,URL从'localhost:3000'更改为' https://singhkshitij.github.io/abc/ ',因此所有图像都将url作为
https://singhkshitij.github.io/images/login-background.png
虽然应该
https://singhkshitij.github.io/abc/images/login-background.png
我将假设您已使用create-react-app
引导您的应用程序。 在这种情况下,您需要在package.json
中将homepage
属性指定为类似
"homepage": "https://singhkshitij.github.io/abc",
参考-https: //facebook.github.io/create-react-app/docs/deployment#building-for-relative-paths
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.