簡體   English   中英

在Header React Router中獲取子組件prop

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM