Reactjs 使用react路由器定义传递额外参数

Reactjs 使用react路由器定义传递额外参数,reactjs,react-router,Reactjs,React Router,我们正在ReactJS中创建路由,即: <Route path="/" component={App}> <IndexRoute component={Home}/> <Route path="/foo" component={SomeComponent} /> </Route> 是的,你能做到 在SomeComponent中,通过this.props.route.params访问params 您将获得从路由传递的参数 <Route

我们正在ReactJS中创建路由,即:

<Route path="/" component={App}>
  <IndexRoute component={Home}/>
  <Route path="/foo" component={SomeComponent} />
</Route>
是的,你能做到

SomeComponent
中,通过
this.props.route.params
访问
params

您将获得从路由传递的参数

<Route path="/" component={App}>
  <IndexRoute component={Home}/>
  <Route path="/foo" component={SomeComponent} params={key: 'foo'} />
  <Route path="/bar" component={SomeComponent} params={key: 'bar'} />
</Route>