【问题标题】:Generate CSS for Server Side Rendering in React - Material-UI在 React 中为服务器端渲染生成 CSS - Material-UI
【发布时间】:2019-02-24 14:39:33
【问题描述】:
【问题讨论】:
标签:
php
css
reactjs
symfony
server-side-rendering
【解决方案1】:
我想你可以将带有 html 模板的 CSS 传递给客户端,就像我在我的一个项目中所做的一样。
const cssStyleTage = extractCSSFromMaterialUIServerSideAPI();
const componentStream = someHtmlConten;
const html = `
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${cssStyleTage}
</head>
<body>
<div id="root">
${componentStream}
</div>
</body>
</html>`;
// pass it to client, this you can open in any iframe at client side.
res.status(200).send(html);
// or otherwise just send the css styles separately.
res.status(200).send({
cssStyleTags: cssStyleTage,
html: componentStream
});
我只是想知道有哪些可能的方法可以完成,如果这可以帮助您完成任务。