React Router Authorization

Updated solution for
React router v4

<Route 
  path="/some-path" 
  render={() => !isAuthenticated ?
    <Login/> :
    <Redirect to="/some-path" />
}/>

React router up to v3

Use ‘onEnter’ event and in callback check if the user is authorized:

<Route path="https://stackoverflow.com/" component={App} onEnter={someAuthCheck}>  

const someAuthCheck = (nextState, transition) => { ... }

Leave a Comment

tech