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