[英]Angular image not showing after deploying to Github Pages
I'm new to Angular.我是 Angular 的新手。 I recently deployed a sample webpage to Github Pages.
我最近向 Github Pages 部署了一个示例网页。 I was successful at deploying but images that are visible on localhost are not showing up.
我已成功部署,但未显示在本地主机上可见的图像。 Instead, I'm getting a 404 logged on the console.
相反,我在控制台上登录了 404。
This is the component containing the img
:这是包含
img
的组件:
home.component.html:主页.component.html:
<div>
<img src='assets/images/birthday.jpg' alt='Happy Birthday' width="385px"/>
</div>
My directory structure is:我的目录结构是:
|src
|--app
|--assets
|---images
|----birthday.jpg
The directory structure in the dist
folder is: dist
文件夹中的目录结构为:
|dist
|--happy-birthday
|--assets
|---images
|----birthday.jpg
I'm deploying using angular-cli-ghpages
package.我正在使用
angular-cli-ghpages
包进行部署。 My Angular version is 10.0.14
.我的 Angular 版本是
10.0.14
。
尝试使用/assets/images/birthday.jpg
。
尝试明确给出一个相对路径( img
相对于home.component.html
路径)下面给出了一个例子,但是这可能会根据您的目录结构而改变。
<div><img src='../assets/images/birthday.jpg' alt='Happy Birthday' width="385px"/></div>
I just tried without the leading slash and it worked: src='assets/images/birthday.jpg'
.我只是尝试不使用前导斜杠,它起作用了:
src='assets/images/birthday.jpg'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.