将URL参数和道具传递给Route的渲染组件

时间:2018-09-28 12:17:01

标签: reactjs react-router

react-router中,为了访问URL参数,您必须使用component的{​​{1}}道具:

<Route>

要将道具传递到渲染的组件,必须使用<Route path="/articles/:id" component={Article} /> //Then use the injected this.props.match.params.id to retrieve the id 的{​​{1}}道具:

render

但是您如何同时传递URL参数和将props传递给渲染的组件呢?

谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

渲染道具的功能在签名中具有路线道具:

<Route path="/articles" render{
  (routeParams) => <PageArticles routeParams={routeParams} width={200} />
}/>

您可以在我制作的this code snippet中看到它

相关问题