首页 > 解决方案 > 更新到 Angular 11 时 BaseHref 在 scss 文件中不起作用

问题描述

我将我的 Angular 版本 profect 从 9 更新到 11,并且在使用 baseHref 编译项目时得到了问题。我已经从在 --base-href 之类的命令中设置 baseHref 更改为 angular.json 文件,并设置构建选项并设置“baseHref”:“/baseHref/”。当我检查浏览器请求时,我注意到从 scss 请求的图像不是使用 baseHref 请求的。我尝试设置 baseHref 和 deployUrl 但不起作用。

标签: angular

解决方案


在 index.html 文件更改

<base href="/">

<base href="./">

并尝试 ng build --prod --base-href ./


推荐阅读