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>
)
}
}
I need to get tabKey prop at header component , so I can change header elements depends on content
You can use render() inside the Route component to pass props. Here's an example:
<Route exact path="/example" render={() => {
return <Child tabKey={1} />;
}} />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.