Angular: теги сценария, сгенерированные до HTML-тега - PullRequest
0 голосов
/ 03 ноября 2019

У меня есть приложение, поданное на localhost:4200 с ng serve.
Когда я нажимаю localhost:4200/home, все работает нормально.
Когда я нажимаю localhost:4200/vehicle/idKind/id, Chrome пытается загрузить localhost:4200/vehicle/idKind/runtime.js, чтоприводит к ошибке 404.
После проверки index.html, сгенерированной угловым cli, я заметил, что теги сценария генерируются перед тегом 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, что я и хочу.

My 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?

1 Ответ

1 голос
/ 04 ноября 2019

вам, вероятно, нужно проверить, написан ли селектор app-root внутри тела, как это показано в index.html

<body>
     <app-root></app-root>
</body>
...