{this.props.children} 和 Parent 的路由参数?
{this.props.children} and route params of Parent?
假设我的路线是这样的
<Router history={browserHistory>
<Route path="/" component={App}>
<Route path="project/:id" component={Project}>
<Route path="info" component={projectInfo} />
<Route path="details" component={projectDetails />
</Route>
</Route>
</Router>
我想从数据库中获取带有 id 的项目,这很明显。但是,如果在 Project 组件中我写 {this.props.children} 我如何将 id 传递给 projectInfo 组件,以便我可以在那里获得信息。还是我不会这样做?
我会使用 in Project 导航到子组件,但我如何获取它们的 ID!!!!!!
您可以使用 this.props.params.id 访问该 ID。
路由 /project/1 将 return id 为 1。
假设我的路线是这样的
<Router history={browserHistory>
<Route path="/" component={App}>
<Route path="project/:id" component={Project}>
<Route path="info" component={projectInfo} />
<Route path="details" component={projectDetails />
</Route>
</Route>
</Router>
我想从数据库中获取带有 id 的项目,这很明显。但是,如果在 Project 组件中我写 {this.props.children} 我如何将 id 传递给 projectInfo 组件,以便我可以在那里获得信息。还是我不会这样做?
我会使用 in Project 导航到子组件,但我如何获取它们的 ID!!!!!!
您可以使用 this.props.params.id 访问该 ID。
路由 /project/1 将 return id 为 1。