![](/img/trans.png)
[英]react-router getting this.props.location in child components
[英]Getting child components prop in Header react router
class RouterConfig extends Component {
render() {
return (
<div>
<HashRouter>
<div>
<Route component={Header}/>
<Switch>
<Route exact={true} path='/' component={Total} tabkey={1}/>
<Route exact={true} path='/news/' component={News} tabkey={2}/>
<Route exact={true} path='/read/' component={ReadNews} tabkey={3}/>
</Switch>
</div>
</HashRouter>
</div>
)
}
}
我需要在标头组件处获取tabKey属性,以便可以根据内容更改标头元素
您可以在Route组件内使用render()来传递道具。 这是一个例子:
<Route exact path="/example" render={() => {
return <Child tabKey={1} />;
}} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.