Prerender.io 与 Angular Universal 一起 - 不会在组件标记中呈现 HTML



我创建了一个由嵌套组件组成的Angular Universal应用程序。 我需要 Prerender.io 才能从我的应用程序返回服务器端呈现的 HTML,但 Prerender.io 只返回顶级组件标记,而不返回其中的 HTML。

似乎每个 Angular 应用程序都会发生这种情况(无论是否为 SRR(。我希望它发生在非 SSR 页面上,但不发生在 SSR 上。

我遵循了 prerender.io 的指导方针:

git clone https://github.com/prerender/prerender.git
cd prerender
npm install
node server.js

然后尝试转到:

http://localhost:3000/http://localhost:4000/test

我得到的返回的 html 是:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Documents SSR</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.3ff695c00d717f2d2a11.css">
<style></style>
</head>
<body>
<app-root _nghost-sc0="" ng-version="8.2.3" _nghost-serverapp-c0="">
<router-outlet _ngcontent-serverapp-c0=""></router-outlet>
<component1>
<!---->
<component2></component2>
</component1>
</app-root>
</body>
</html>

我希望 Prerender.io 渲染component2中的所有内容,但正如你所看到的,我什么也得不到。

我是否在某处缺少配置或 Prerender.io 不支持 Angular?

如果我直接转到http://localhost:4000/test我会得到完整的渲染 HTML。

编辑

看起来Prerender.io 在渲染之前没有等待我的最后一个 ajax 调用完成?

发现问题 - 不要使用 ShadowDom。 我的component2正在使用encapsulation: ViewEncapsulation.ShadowDom. 删除它让预渲染给我整个 HTML。

最新更新