Answer the question
In order to leave comments, you need to log in
How to force React Router to update content when navigating similar pages with the same Handler with dynamic path?
I have this Route:
<Route name="itemDetails" handler={ItemDetails} path="/item/:id"/>
Answer the question
In order to leave comments, you need to log in
What version of react, router?
Try using the componentWillReceiveProps method - it should be called when the route parameters (in your case, the ID) change.
When the component receives new properties (props) - it is redrawn. The problem can be if you, for example, use the parameters of your route through state:
class ControllerComponent extends Component {
super() {
super(props);
this.state = { itemId: this.getParams().id };
}
//...
render() {
return (
<div>
<p>Blah blah blah</p>
<SomeComponent itemId={this.state.itemId}/>
</div>
);
}
}
class ControllerComponent extends Component {
super() {
super(props);
this.state = { itemId: this.getParams().id };
}
componentWillReceiveProps(nextProps) {
this.setState({ itemId: this.getParams().id });
}
//...
render() {
return (
<div>
<p>Blah blah blah</p>
<SomeComponent itemId={this.state.itemId}/>
</div>
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question