相关疑难解决方法(0)

react-router:在没有Redux的路由之间共享状态

我想在两个兄弟路由之间建立一个共享状态(远程获取的客户端列表):TimesheetsClients.
我想尝试用"纯粹的"React(No Flux架构)走多远.

这个例子有效,但我有一个错误:browser.js:49 Warning: [react-router] You cannot change <Router routes>; it will be ignored 所以,它似乎不喜欢异步道具.

constructor(props) {
   super(props);
   this.state = {
      clients : []
   }
}

componentDidMount() {
   fetch("clients.json")
     .then(response => response.json()) 
     .then(clients => this.setState({ clients }));
}

render() {
  return (
    <Router history={browserHistory}>
      <Route path="/" component={Header} >
        <Route path="timesheet" component={() => (<Timesheets {...this.state} />) }/>
        <Route path="clients" component={() => (<Clients {...this.state} />) }/>
      </Route>
    </Router>
  );
}
Run Code Online (Sandbox Code Playgroud)

是否可以向每条路线发送异步道具?
或者是否可以在父路由(Header组件)中设置整个状态,然后从每个子路由(Timesheets和 …

reactjs react-router

4
推荐指数
1
解决办法
5442
查看次数

标签 统计

react-router ×1

reactjs ×1