score:2

Accepted answer

Your <Lesson /> component only sets the lesson during the componentDidMount lifecycle hook. If you're on a lesson and you change the slug, it does not cause the component to remount. You can use the componentWillReceiveProps lifecycle hook to accomplish what you're after.

componentWillReceiveProps(nextProps) {
    api.getLesson(nextProps.match.params.lesson)
        .then((lesson) => {
            this.setState({
            lesson: lesson[0]
        });
    });
}

score:0

This issue with componentDidMount event. It's not fired when you change Lesson. So you should use componentDidUpdate to change a lesson.

  componentDidUpdate() {
    if (this.props.match.params.lesson !== this.state.lesson.slug)
     api.getLesson(this.props.match.params.lesson)
          .then((lesson) => {
            this.setState({
              lesson: lesson[0]
            });
          });
        }
      }

Related Query

More Query from same tag