I have a route defined as follows:
<Route exact path="/licenses/:type?" component={Licenses} />
I want my component to re-render when the type parameter changes, so, as mentioned in react-router documentation, I need to use a key. I want the value of key same as param passed to the route. Something like:
<Route exact path="/licenses/:type?" key=":type" component={Licenses} />
But I am unable to get the value of the type parameter as key. Is there any way to set the key same as type parameter's value?
Got it!
I should use render
instead of component
like this:
<Route
exact
path="/licenses/:type?"
render={props => <Licenses key={props.match.params.type || 'empty'} /> }
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With