onEnter not called in React-Router
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 providesonEnter
,onUpdate
, andonLeave
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 ofonEnter
, you would usecomponentDidMount
orcomponentWillMount
. Where you would useonUpdate
, you can usecomponentDidUpdate
orcomponentWillUpdate
(or possiblycomponentWillReceiveProps
).onLeave
can be replaced withcomponentWillUnmount
.
onEnter
no longer exists on react-router-4
. You should use <Route render={ ... } />
to get your desired functionality. I believe Redirect
example has your specific scenario. I modified it below to match yours.
<Route exact path="/home" render={() => (
isLoggedIn() ? (
<Redirect to="/front"/>
) : (
<Home />
)
)}/>