React组件没有收到道具

Sim*_*leJ 0 javascript reactjs react-router babeljs

我试图从React路由器向我的组件传递一些参数,但由于某种原因,一旦组件被渲染,参数就不再存在了.

这是我的代码:

路由器:

var routes = (
    <Route handler={require('components/forum-app')}>
        <DefaultRoute       handler={require('components/post-list')}/>
        <Route name='posts' handler={require('components/post-list')}/>
        <Route name='post'  handler={require('components/post')}        path='/post/:postId'/>
    </Route>
);

Router.run(routes, function(Handler, options) {
    React.render(<Handler {...options}/>, document.body);
});
Run Code Online (Sandbox Code Playgroud)

邮政部分:

var Post = React.createClass({
    render: function() {
        console.log(this.props);
        return (
            <div>
            </div>
        );
    }
});
Run Code Online (Sandbox Code Playgroud)

当我访问路径时#/post/post-1,post render方法打印一个空对象.我已检查并确保回调中的options变量Router.run具有属性.

任何帮助将不胜感激.

nil*_*gun 6

你的Post类嵌套在forum-app课堂上.因此,您还应该将forum-app类中的属性传递给其嵌套组件:

<Router.RouteHandler {...this.props}/>
Run Code Online (Sandbox Code Playgroud)