首页 > 解决方案 > 如何将道具传递给我的孩子路线?

问题描述

我有一条要传递 locationId 道具的子路线。

我尝试将 locationId={locationId} 添加到我的路线中,但这没有用。

return (
  <div>
      <Route path={`${this.props.match.url}/users/:userId`} component={CardsShowView} />
  </div>
);

有可能以某种方式传递这个道具吗?

标签: reactjs

解决方案


<Route path={`${this.props.match.url}/users/:userId`} render={() => 
<CardsShowView locationId={locationId}/>} />

你可以使用render道具。

如果你真的想要这个位置,你可以这样做。

<Route path={`${this.props.match.url}/users/:userId`} render={(props) => 
<CardsShowView locationId={props.location}/>} />

推荐阅读