英文:
"Failed to load resource" error when loading photos on github pages with reactjs
问题
我最近在 GitHub Pages 上部署了一个 React 网站,但我的照片一直无法加载。我不确定问题是什么。
GitHub Pages 网站:https://connoryoung2.github.io/photo-gallery/
GitHub 存储库:https://github.com/connoryoung2/photo-gallery
我尝试过更改照片的目录(例如,从 ./photos/photo.png 改为 ../photos/photo.png),并确保每个链接到照片的链接都拼写正确。也许我做错了什么。
英文:
I recently deployed a react website on github pages but my photos keep failing to load. I'm not sure what the problem is
github pages website: https://connoryoung2.github.io/photo-gallery/
github repo: https://github.com/connoryoung2/photo-gallery
I have tried changing the directory of the photos (ie. ./photos/photo.png to ../photos/photo.png) and making sure that each link to each photo is capatilized correctly. Maybe I'm doing this wrong though.
答案1
得分: 1
Sure, here's the translated content:
像这样写
<img src="/photo-gallery/photos/stel_curt.jpg" alt="Gallery Image" class="home-img img-fade active">
(只适用于捆绑工具)您还可以在组件中导入照片并插入img src,然后您的路径将正常。
import photo from './photos/lmK8L8nRkqk.jpg';
export default function App() {
return <img src={photo} alt="" />;
}
英文:
write like this
<img src="/photo-gallery/photos/stel_curt.jpg" alt="Gallery Image" class="home-img img-fade active">
(it works only with bundlers) you can also import photo in component and insert in img src and then your paths will be alright
import photo from './photos/lmK8L8nRkqk.jpg';
export default function App() {
return <img src={photo} alt="" />;
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论