【发布时间】:2018-07-11 03:31:08
【问题描述】:
有没有办法使用 react-router 将 props 从 Parent 组件传递到 Child 组件?
<Route path="/parent/" component={Parent} />
<Route path="/parent/child/" component={Child} />
注意 Child 没有在 Parent 的渲染函数中渲染。
谢谢
【问题讨论】:
-
一开始为什么会有这样的层次结构?
-
也许这是一个愚蠢的想法,但我的组件在父级中呈现的所有子级路由(例如页眉、页脚)中都是一致的。这样它就不必在所有子路由更改时重新渲染。
-
所以你应该在 Parent 中使用 Route。见stackoverflow.com/questions/41474134/…
标签: reactjs react-router