[英]ANGULAR 11 - When I build my angular web app and deploy my hosting, couldn't get images from assets
I have an Angular11 web app.我有一个 Angular11 web 应用程序。 When I build and deploy the app to my host, there is a "GET http//../assets/image.png" error.
当我构建应用程序并将其部署到主机时,出现“GET http//../assets/image.png”错误。 I don't know how to fix it?
我不知道如何解决它? Can anyone please help me?
谁能帮帮我吗?
Here is my HTML code:这是我的 HTML 代码:
<img class="pic" src="../../assets/pic.png" alt="">
**I am sure that my image path is absolutely true. **我确信我的图像路径是绝对正确的。
And angular.json:和 angular.json:
"assets": [
"src/favicon.ico",
"src/assets",
"src/.htaccess"
],
I have tried to change <img class="pic" src="../../assets/pic.png" alt="">
to <img class="pic" src="/assets/pic.png" alt="">
but doesn't work.我试图将
<img class="pic" src="../../assets/pic.png" alt="">
更改为<img class="pic" src="/assets/pic.png" alt="">
但不起作用。
And I also realize that when I am moving it to (public-html/fileName/MYAPPISHERE) path into the host but the error is like "GET https//.....com/assets/image.png".而且我还意识到,当我将它移动到主机的(public-html/fileName/MYAPPISHERE)路径时,错误就像“GET https//.....com/assets/image.png”。 Shouldn't it be like "https//..com/fileName/assets/image.png"?
它不应该像“https//..com/fileName/assets/image.png”吗?
If it's a manual deployment/build, I guess you miss the base-href
option that allow you to specify the subfolder your app is deployed in. So the command should be something like:如果它是手动部署/构建,我猜您错过了
base-href
选项,该选项允许您指定部署应用程序的子文件夹。因此命令应该类似于:
ng build --prod --base-href /fileName/
to tell the builder to build the pathes (To the assets and API call and others) with the specified subfolder.告诉构建器使用指定的子文件夹构建路径(到资产和 API 调用等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.