在github页面上部署angular应用程序后未加载图像
我使用以下命令在github页面上部署了一个测试项目:在github页面上部署angular应用程序后未加载图像,angular,image,github,deployment,github-pages,Angular,Image,Github,Deployment,Github Pages,我使用以下命令在github页面上部署了一个测试项目: ng build --prod --base-href https://<profile_name>.github.io/<repo_name>/ ngh --dir=dist/scrabble angular.json中的资产: "outputPath": "dist/scrabble/", "assets": [ "src/favicon.ico", "src/assets" ], 带有图像的资产文
ng build --prod --base-href https://<profile_name>.github.io/<repo_name>/
ngh --dir=dist/scrabble
angular.json中的资产:
"outputPath": "dist/scrabble/",
"assets": [
"src/favicon.ico",
"src/assets"
],
带有图像的资产文件夹位于/src/assets
图像标记的一个示例,它在本地主机上运行良好,但在github页面上无法加载:
<img src="../../../assets/scaledlogo.png" routerLink="/menu" />
您需要传递--部署url选项。你的情况应该是这样的
ng build--prod--base hrefhttps://.github.io// --部署url=https://.github.io//
如果您的所有图像都在资产文件夹中,您只需从路径中删除。/
s即可
<img src="assets/scaledlogo.png" routerLink="/menu" />
所以问题是所有内容都被传输和缩小,资产文件夹不再是3个目录。Angular知道您的资产文件夹在本地运行还是部署,不需要相对路径。删除前面的“./”并提及从资产文件夹开始的路径
下面将解决您的问题
<img src="assets/scaledlogo.png" routerLink="/menu" />
如果资产中有其他文件夹,请继续使用该路径。
例如:
<img src="assets/images/leave-procedure/admin1.png" width="400" height="150">
希望这有帮助。要检查的事项列表:
- 如果确实有效,则可能是配置文件(如angular.json)下的路径设置有问题
- 很可能是后端中的重定向代码。尝试更改文件名
你还能在本地提供文件吗?@TonyNgo我不知道这是什么意思这很有效,谢谢