简体   繁体   English

如何将this.state转换为react-routes?

[英]How to transfer this.state to react-routes?

I use the react-router and ES6, both in the new react-router to pass a value to the component? 我在新的react-router中都使用了react-router和ES6来将值传递给组件? I used use <Handler name = {this.state.name} /> now used {this.props.children} . 我曾经使用<Handler name = {this.state.name} />现在使用了{this.props.children} How to transfer data to it from the App in the Components? 如何从组件中的应用程序向其传输数据?

How to transfer this.state to react-routes with: 如何将this.state传递给具有以下功能的反应路由:

export default class App extends React.Component{

  constructor () {
    this.state = { name: 'Username' };
  }

  render () {
    return (
      <div>
        {this.props.children} // <-- this.state ???
      </div>
    );
  }
};

React.render((
  <Router history={HashHistory}>
    <Route path="" component={App}>
      <Route path="about" component={About} />
    </Route>
  </Router>
), document.getElementById('app'));

{this.props.children} // <-- this.state ??? {this.props.children} // <-this.state ???

I would recommend to access the information you store in App.state from separate Flux stores and then access them in each component you need. 我建议从单独的Flux商店访问存储在App.state中的信息,然后在所需的每个组件中访问它们。 React router should not be involved into passing the data between routes. React路由器不应参与路由之间的数据传递。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM