简体   繁体   English

如何将React.js组件从node.js发送到客户端?

[英]How could I send a React.js component from my node.js to my client?

I'm sending a client a loader, and I want to receive my main React.js components from the server, after rendering the loader. 我正在向客户端发送一个加载器,并且在渲染加载器之后,我想从服务器接收我的主要React.js组件。

I'm using node.js with express on the backend and i'm using the "express-react-views" engine for rendering. 我正在后端使用带有express的node.js,并且正在使用“ express-react-views”引擎进行渲染。

So, how can I safely transfer components from the server to the client? 那么,如何安全地将组件从服务器传输到客户端?

Thanks a lot. 非常感谢。

    var htmlOfComponent = ReactDOMServer.renderToString(component);
  1. send this htmlOfComponent as part of your initial html page request from server. 发送此htmlOfComponent作为服务器最初的html页面请求的一部分。

  2. include react.js in script tags and send. 在脚本标签中包含react.js并发送。

  3. For component data=> you can send that stringified in script tags too. 对于组件数据=>,您也可以将其字符串化发送到脚本标签中。

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

相关问题 无法从我的客户端(react.js)获取数据(node.js) - Not able to get data (node.js) from my client (react.js) 如何从我的 Node.JS 向我的 Javascript 客户端发送一个警报? - How can I send one alert from my Node.JS to my Javascript client? 如何将图像从Node.js发送到React.js? - How can I send an image from Node.js to React.js? 如何从我的本地主机获取? 将 React.js 连接到 Node.js - How to Fetch from my local host? Connect React.js to Node.js 从 Node.JS 服务器应用程序中发出 GET 请求并将其发送到 React.JS 客户端 - Make a GET request from within a Node.JS server app and send it to React.JS client 如何使用 React.js 和 Node.js 仅将所需资源加载到客户端浏览器 - How can I load only required resources to client browser with React.js and Node.js React.js, Node.js : 在 React 中发送 axios 请求 - React.js, Node.js : send axios request in React 如何在Node.js脚本中从Gmail帐户发送电子邮件? - How do I send email from my Gmail account in my Node.js script? 服务器端和客户端端的路由-React.js和Node.js - Routes on server & client side - React.js & Node.js 在 GraphQL 服务器中将数据从服务器(Node.js)发送到客户端(React 组件) - Send data from server(Node.js) to client(React Component) in GraphQL server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM