Angular : 在 html 标签之前生成的脚本标签

Angular : script tags generated before html tag

我在 localhost:4200 上投放了一个应用 ng serve
当我点击 localhost:4200/home 时,一切正常。
当我点击 localhost:4200/vehicle/idKind/id 时,Chrome 尝试加载 localhost:4200/vehicle/idKind/runtime.js,这导致 404 错误。
检查 angular cli 生成的 index.html 后,我注意到脚本标签是在 html 标签之前生成的:


<script src="runtime.js" type="module"></script><script src="polyfills.js" type="module"></script><script src="styles.js" type="module"></script><script src="scripts.js" defer></script><script src="vendor.js" type="module"></script><script src="main.js" type="module"></script><script src="runtime.js" type="module"></script><script src="polyfills.js" type="module"></script><script src="styles.js" type="module"></script><script src="scripts.js" defer></script><script src="vendor.js" type="module"></script><script src="main.js" type="module"></script>
<!doctype html>
<html lang="fr">

<head>
    <base href="/">
    <!-- some scripts, stylesheets and fonts -->
    <title>My app</title>

</head>
<app-root></app-root>

</html>

当我在 <head>(和 <base href="/" />)之后手动放置它们时 Chrome 尝试加载 localhost:4200/runtime.js,这是我想要的行为。

我的 src/index.html :

 <!doctype html>
<html lang="fr">

<head>
    <base href="/">
    <!-- some scripts, stylesheets and fonts -->
    <title>My app</title>

</head>
<app-root></app-root>

</html>

为什么我的脚本标签在 html 之前生成?

您可能需要检查 app-root 选择器是否像这样在 index.html

中写在正文中
<body>
     <app-root></app-root>
</body>