search

Home  >  Q&A  >  body text

javascript - How to achieve the previous onEnter effect in react-router version 4.0

I checked the official documents and it doesn’t seem to mention this

三叔三叔2709 days ago893

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-07-05 11:05:58

    React Router v3 provides onEnter, onUpdate, and onLeave methods. These were essentially recreating React's lifecycle methods.

    With v4, you should use the lifecycle methods of the component rendered by a <Route>. Instead of onEnter, you would use componentDidMount or componentWillMount. Where you would use onUpdate, you can use componentDidUpdate or componentWillUpdate (or possibly componentWillReceiveProps). onLeave can be replaced with componentWillUnmount.

    reply
    0
  • Cancelreply