0
リア・ルータv2からv4にアプリを移行しています。リアクションルータv2をv4のonEnter引数にマイグレーション
古いv2のコードは次のようになります。
<Route path="/configurations/:id" onEnter={loadConfiguration}>
// some stuff
</Route>
新しいv4のコードは次のようになります - nextState
<Route path="/configurations/:id" component={MyComponent}>
// some stuff
</Route>
export default class MyComponent extends Component {
componentDidMount() {
loadConfiguration()
}
// render method, etc
}
問題はloadConfiguration機能v2の中3つのparamsと呼ばれているということです置換、コールバック
v4コードでは、loadConfiguration関数は0個のパラメータで呼び出されます。
v2からv4への移行時にloadConfigurationに同じ値を渡すにはどうすればよいですか?
<Route path="/configurations/:id" render={
() => <MyComponent nextState={ nextState } replace={ replace } callback={ callback } />
} />
そして、あなたのコンポーネントで:
export default class MyComponent extends Component {
loadConfiguration() {
...
}
componentDidMount() {
this.loadConfiguration(this.props.example, this.props.replace, this.props.callback)
}
// render method, etc
}
ます。また、親からloadConfiguration機能をダウン渡すことができ