传递道具
您可以通过
state对象将任意道具传递到路线:
<link to={{ pathname: '/route', state: { foo: 'bar'} }}>My route</link>然后,您可以
state从组件内部访问对象:
const {foo} = props.location.stateconsole.log(foo) // "bar"传递参数
配置您的路由路径以接受命名参数(
:id):
<Route path='/route/:id' exact component={MyComponent} />然后,您可以在链接中传递URL参数(例如ID)
to:
<link to={`route/foo`}>My route</link>您可以通过
match对象在组件内访问参数:
const {id} = props.match.paramsconsole.log(id) // "foo"资料来源
https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/location.md
https://github.com/ReactTraining/react-router/issues/4036



