reactjs - react-router 将先前的路由道具传递给子路由
问题描述
有没有办法使用 react-router 将 props 从 Parent 组件传递到 Child 组件?
<Route path="/parent/" component={Parent} />
<Route path="/parent/child/" component={Child} />
注意 Child 没有在 Parent 的渲染函数中渲染。
谢谢
解决方案
我认为这里一个好的解决方案是带有渲染道具的嵌套路由。
// Parent.jsx
render() {
const { match: { url }, xyz } = this.props;
return (
<Route path={`${url}/child`} render={() => <Child xyz={xyz} />}
);
}
推荐阅读
- javascript - 将 onload 添加到元素而不在 Puppeteer 中执行
- php - 尝试从自定义插件访问 Elmntor-pro base-widget.php 时出错
- javascript - 传单装饰器抛出此错误“错误:无效的 LatLng 对象:(NaN,NaN)”
- node.js - $lookup 在多个数组对象中的两个集合
- php - CSRF Token 不匹配,laravel 和 axios
- python - YawOptimizationWindRoseParallel() 需要什么 MPI 实现?
- c - CMake错误的* .so文件路径
- r - GlmmNP 包给了我错误
- python - 如何在 PyCharm 上安装 NumPy?
- python - 从 Python 3.8 运行 Excel 宏