0
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 소품을 얻을 필요가 라우터에게
헤더 구성 요소의 스위치 블록에서 렌더링 된 구성 요소를 식별 할 수있는 방법이 있습니까? – shijin
물론입니다. Header 구성 요소의 경로 경로를 path = "/"로 설정하십시오. 모든 경우에 호출되며, 헤더에서 props.location.pathname을 사용하여 호출 된 경로를 가져옵니다. props.location.pathname이/news이면 News 구성 요소가 호출되는 식으로 계속됩니다. – raksheetbhat