0
我在我的应用程序使用react-router
,它看起来是这样的:获取组件儿童型阵营
<Router history={hashHistory}>
<Route path="/" component={Root}>
<Route path="about" component={Child1} />
<Route path="about" component={Child2} />
// and so on...
</Route>
</Router>
我想知道这是传下来的每一次Root
孩子的类型有一个变化。事情是这样的:
if(typeof this.props.children === Child1) {
// do stuff
}
如果组件只包含一个孩子,'this.props.children'返回上而不是单个元素的数组。 – cynicaldevil
@cynicaldevil:**哇**,我不知道。太疯狂了。无论如何,希望我在编辑中提到的“类型”是有帮助的。 –
是的,它的工作!谢谢! – cynicaldevil