reactjs - 如何将道具传递给我的孩子路线?
问题描述
我有一条要传递 locationId 道具的子路线。
我尝试将 locationId={locationId} 添加到我的路线中,但这没有用。
return (
<div>
<Route path={`${this.props.match.url}/users/:userId`} component={CardsShowView} />
</div>
);
有可能以某种方式传递这个道具吗?
解决方案
<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}/>} />
推荐阅读
- api - 无法读取未定义的属性“employee_name”
- sql - 如何声明变量并将输出作为表
- google-apps-script - 成功生成 PDF,但添加二维码时失败
- laravel - 为虚拟主机 laravel 提供 SSL 证书
- javascript - 如何随机插入一个问题数组的条目及其答案映射到另一个数组
- c# - .net core hangfire 运行特定任务
- flutter - 当我运行颤振项目时,这显示 Dart 编译器意外退出的错误
- reactjs - 当聊天本地存储在客户端计算机中时,在聊天应用程序中实现删除消息功能
- javascript - Promise 不可分配给 React 状态
- amazon-web-services - 无法以任何方式将 aws 环境带入健康状态。它说-*Environment named is in an invalid state for this operation。必须准备好*