ルートプロップをルートプロップで初期APIリクエストを実行するレイアウトコンポーネントに渡そうとしていますが、これらのルートプロップは子プロセスにのみ渡されるという問題がありますルート。明らかにReact Router 4:ルートコンポーネントをレイアウトコンポーネントに渡す
<BrowserRouter>
<Switch>
<AppLayout> // This AppLayout performs API requests
// with the :route param in the child routes.
<Route path="/some/:route" component={SomeComponent} />
<Route path="/some/other/:route" component={OtherComponent} />
</AppLayout>
</Switch>
</BrowserRouter>
、ユーザーが/some/:route
ルートに当たると、レイアウトが既にレンダリングされていたであろう。
<BrowserRouter>
<Route path="/some/:route" render={(props) =>
(<AppLayout {...props}><SomeComponent /></AppLayout>)} />
</BrowserRouter>
これは動作しますが、AppLayoutをアンマウントすると私は同じレイアウトを使用して別のルートに行くたびに再マウントします:私はこのような何かをやってみました。反応-ルータ3で
は、私はこのような何かができる:
<Router history={browserHistory}>
<Route path="/" component={AppLayout}>
<Route path="/some/:route" component={SomeComponent} />
<Route path="/some/other/:route" component={OtherComponent} />
</Route>
</Router>
とルートの小道具はAppLayoutコンポーネント上で利用できるようになります。
実際に反応ルータ4でこれを達成する方法はありますか?私はAppLayout
にルータの小道具を渡すと、両方のルートのハンドラとしてAppLayout
コンポーネントを使用していますか
<BrowserRouter>
<Switch>
<Route exact path="/" render={props => <AppLayout {...this.props} />} />
<Route exact path="/some/:route" component={AppLayout} />
<Route exact path="/some/other/:route" component={AppLayout}/>
</Switch>
</BrowserRouter>
注意:あなたが巣のルートにしたいので
おかげで、これはむしろ逆効果と思われるが、これは、と前に可能であった特別なことから、動作しているようですはるかに簡単なアプローチ。 – user3376486
はい、それは逆効果です。反応ルータ3でのルートの処理は、より簡単で簡単でした。 –