onEnter not called in React-Router

后端 未结 2 1841
刺人心
刺人心 2020-12-01 02:29

Ok, I\'m fed up trying.
The onEnter method doesn\'t work. Any idea why is that?

// Authentication \"before\" filter
function requireAuth(ne         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 03:22

    From react-router-v4 onEnter, onUpdate, and onLeave is removed, according the documentation on migrating from v2/v3 to v4:

    on* properties
    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 . 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.

提交回复
热议问题