if I'm on a movie page
/movie/some-movie
and go on link to
/movie/another-movie
component not render
react-route v4
router
<Route exact path="/movie/:urlRusLat" component={Movie} />
link
<Link to={'/' + item.media_type + '/' + urlRusLat(item.title || item.name) + '-' + item.id} className="result-element" key={index}>
I try use componentWillReceiveProps and send request, but i receive in props new location, like in nextProps.
componentWillReceiveProps(nextProps) {
console.log(this.props)
if (this.props.location.pathname !== nextProps.location.pathname) {
this.sendRequest();
}
}
componentDidMount() {
this.sendRequest();
}
componentWillUnmount() {
this.props.clearMovieData();
}
sendRequest = () => {
let movieId = this.props.location.pathname.split('-');
this.props.loadMovieData(movieId[1]);
}
How can i make send request if path change, or render component again?
asked Oct 23, 2017 at 17:46
Drop
1,5923 gold badges17 silver badges28 bronze badges
-
Please provide the code. It's tough without actually code to look at.Max Millington– Max Millington2017年10月23日 18:14:11 +00:00Commented Oct 23, 2017 at 18:14
1 Answer 1
You can use componentDidUpdate() to call the sendRequest() function. Now you get the updated props. But make sure you add a check that oldProps.location != props.location before making a sendRequest() call.
answered Oct 24, 2017 at 3:59
Basavaraj Sonnad
2151 silver badge8 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js