简体   繁体   English

angular baseHref 对索引没有影响。html 链接

[英]angular baseHref no impact on index.html links

In angular I used to run my build command with the --base-href \myapp syntax.在 angular 中,我曾经使用 --base-href \myapp 语法运行我的构建命令。

Now I updated to angular 13 and this command line property is not anymore available.现在我更新到 angular 13 并且这个命令行属性不再可用。 So I added the property to angular.json: ...configurations/"test"/baseHref: "\myapp"所以我将属性添加到 angular.json: ...configurations/"test"/baseHref: "\myapp"

But this seems to be not enough.但这似乎还不够。 This setting will add a <base href="/myapp"> in the index.html head tag.此设置将在 index.html 头标签中添加<base href="/myapp"> But it will not change the other links in index.html like:但它不会改变 index.html 中的其他链接,例如:

<link rel="stylesheet" href="styles.5fe3fd16ea7e146e.css">

So at runtime i get a 404 because styles....css cannot be found in the root, but should reference "myapp/styles....css".所以在运行时我得到一个 404,因为 styles....css 在根目录中找不到,但应该引用“myapp/styles..css”。

Where can I set baseHref so it also affects the links in index.html?我在哪里可以设置 baseHref,这样它也会影响 index.html 中的链接?

It seems that the command line parameter 'base-href' needs to be replaced with the two properties 'baseHref' and 'deployUrl' in angular.json.看来命令行参数'base-href'需要替换为angular.json中的'baseHref'和'deployUrl'这两个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM