【发布时间】:2019-02-03 20:02:01
【问题描述】:
const Home = () => <div>Home</div>
const App = () => {
const someVariable = true;
return (
<Switch>
{/* these are good */}
<Route exact path='/' component={Home} />
<Route
path='/about'
render={(props) => <About {...props} />}
/>
</Switch>
)
}
const About = (props) => {
return (
<div>
About
</div>
)
}
在代码示例中,在
<Route
path='/about'
render={(props) => <About {...props} />}
/>
当 react 遇到 react-router 的 Route 组件的 render prop 时,它传递了什么 props?
鉴于https://reactjs.org/docs/render-props.html 的文档, 渲染道具是组件用来知道要渲染什么的函数道具, 是在 react-router 中的 Route 声明中传递的 props 传递的值
【问题讨论】: