部署在 github 页面上的应用程序将资产的 GET 发送到错误的地址



我使用以下方法构建了我的应用程序:

ng build --prod --base-href https://3hdw.github.io/zpi-frontend/

我注意到部署的应用程序无法加载某些图像。

正确加载的图像通过GET发送到以下地址获得:https://3hdw.github.io/zpi-frontend/assets/fileName
由于某种原因,应用程序尝试使用错误的地址加载其他图像:https://3hdw.github.io/assets/fileName,这导致无法加载某些资产。

在更新我的角度项目后,我注意到了这种行为。

编辑:

未加载的图像使用 css: background-image: url("/assets/fileName");
指定加载的图像使用 html: <img src="assets/fileName"/> 指定

url("/assets/fileName")更改为url("/zpi-frontend/assets/fileName")图像后,正在加载图像,但应该有更好的解决方案

运行 ng build 命令时尝试使用 --deployUrl。这将设置资产前缀。

相关内容

最新更新