相关疑难解决方法(0)

从ReactJS外部渲染组件

这里:

"在React之外获取React Component实例句柄的唯一方法是存储React.render的返回值."

我需要在React之外渲染一个React组件,我将在下面提到它的原因.

在我的node.js,expressJS应用程序中,我使用'react-router-component''react-async'.

在app.js中 - 应该运行的文件,

    var url=require('url');   
    var App=require('./react/App.jsx');
    var app = express();
    app.get('*',function(req,res){


    //}); SEE EDIT 1 BELOW

    var path = url.parse(req.url).pathname;
                ReactAsync.renderComponentToStringWithAsyncState(App({path:path}),function(err, markup) {
    res.send('<!DOCTYPE html>'+markup);

          });
   });
Run Code Online (Sandbox Code Playgroud)

在App.jsx中,

   PostList = require('./components/PostList.jsx');
   var App = React.createClass({
   render: function() {
        return (

           <html>
           <head lang="en">
           </head>
        <body>
        <div id="main">

        <Locations path={this.props.path}>

          <Location path="/" handler={PostList} />
          <Location path="/admin" handler={Admin} />
        </Locations>


       <script type="text/javascript" src="/scripts/react/bundle.js"></script>
       <script type="text/javascript" src="/scripts/custom.js"></script>                 

        </body>
        </html>
        }); 
Run Code Online (Sandbox Code Playgroud)

bundle.js …

node.js express reactjs react-jsx react-async

9
推荐指数
1
解决办法
6842
查看次数

标签 统计

express ×1

node.js ×1

react-async ×1

react-jsx ×1

reactjs ×1