2017-12-27 18 views
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小道具を取得する必要があるので、私はヘッダ要素を変更することができ、ルータ

答えて

0

に依存。ここに例があります:

<Route exact path="/example" render={() => { 
    return <Child tabKey={1} />; 
}} /> 
+0

私は、ヘッダーコンポーネントのスイッチブロックに表示されているコンポーネントを特定する必要がありますか? – shijin

+0

確かに。ヘッダーコンポーネントのルートパスをpath = "/"と設定します。つまり、すべての場合に呼び出され、ヘッダーでは、呼び出されたパスを取得するためにprops.location.pathnameを使用します。 props.location.pathnameが/ newsの場合、Newsコンポーネントが呼び出されました。 – raksheetbhat