4

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
1
  • Please provide the code. It's tough without actually code to look at. Commented Oct 23, 2017 at 18:14

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.