如何转移.State to reaction -routes

How to transfer this.state to react-routes?

本文关键字:State to reaction -routes 转移 何转移      更新时间:2023-09-26

我使用react-router和ES6,都在新的react-router中传递一个值给组件?我以前用的是<Handler name = {this.state.name} />,现在用的是{this.props.children}。如何将数据从组件中的应用程序传输到它?

如何传输这个。

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。//<——this。国家? ?

我建议从单独的Flux存储中访问存储在App.state中的信息,然后在需要的每个组件中访问它们。React路由器不应该参与到路由间的数据传递中。