0

I have an Angular11 web app. When I build and deploy the app to my host, there is a "GET http//../assets/image.png" error. I don't know how to fix it? Can anyone please help me?

Here is my HTML code:

<img class="pic" src="../../assets/pic.png" alt="">

**I am sure that my image path is absolutely true.

And 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.

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". Shouldn't it be like "https//..com/fileName/assets/image.png"?

1 Answers1

0

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 :

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.

Quentin Grisel
  • 4,794
  • 1
  • 10
  • 15
  • thanks for the answer, I tried this or --deploy-url... but not work for me – Kadri Çabuk Feb 01 '21 at 22:45
  • @KadriÇabuk Then could you please edit your answer with more details about that because what you said at last show that the path is incorrect (You might need to use both `base-href` and `deploy-url`. And looks like the last slash at the end is important as commented here https://stackoverflow.com/a/55666548/9868549). Also tell us where you aredeploying your app. Is it on the cloud ? which one ? IIS ? – Quentin Grisel Feb 01 '21 at 22:57