[英]React: how to mix server-side HTML with react components and functions
[英]Server-side React with pure components
我正在嘗試構建一個遵循最佳實踐的同構React應用程序。 我目前僅在嘗試為服務器找到一個好的系統。 這是我的一些要求:
props
我制作了一個示例應用程序,用來說明我的問題/困惑: https : //github.com/maximilianschmitt/ipman
基本上, 組件樹如下所示:
RouteHandler
App
RouteHandler
Home
Ip
routes.js
'use strict';
const Router = require('react-router');
const App = require('./components/app');
const Home = require('./components/home');
const Ip = require('./components/ip');
const Route = Router.Route;
const routes = (
<Route handler={App}>
<Route name="home" path="/" handler={Home} />
<Route name="ip" path="/ip" handler={Ip} />
</Route>
);
module.exports = routes;
組件/ip.js
class Ip extends React.Component {
render() {
return <div>Your ip is: {this.props.ip || 'undefined'}</div>;
}
}
/ip
,我希望服務器從http://ip.jsontest.com請求其自己的IP地址,以某種方式將其傳遞給Ip
組件,然后將所有內容呈現為字符串,以供客戶端查看HTML。 props
傳遞必要的信息 我知道alt.js之類的庫和其他同構的磁通量實現通過存儲的概念解決了這個問題,但是我想知道這是否有點過分。
是否有添加所需功能的簡單方法?
根據react-router的這篇文章,我得到了一些似乎不是很糟糕的解決方案。 您可以在這里找到結果: https : //github.com/maximilianschmitt/server-side-react
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.