title: React, React-Router, access-token and session time out
body: <p>I have difficult to take the next step in my solution, and I would much appreciate any help. :)</p>
  
  <p>The LoginForm component is used to authenticate and if success, an access-token will be returned and stored in localStorage.</p>
  
  <p>I try to implement some kind of session time out function that will redirect the user to the LoginForm component if the access-tokens has run out of time. I have created an api endpoint for this and try to use it in the onEnter hook function for the protected routes.</p>
  
  <p>The redirectToLogin function do a call to this endpoint and if error it should redirecto to the LoginForm. The LoginForm always check if the access token exist in local storage, if so, it "knows" a session time out has happened and can display a proper message.</p>
  
  <p>The problem seems that the redirectToLogin function only executes when I navigate from the / route to a protected route and not when I navigate lets say between /users to /users/:id </p>
  
  <p>I'm sure I do not unserstand the router properly and I really really would appreciate any help?</p>
  
  <p>My routing logic looks like this.</p>
  
  <pre><code>let routes = { 
    // Base component render an AppBar component and if the access token 
    // is stored in localStorage, the Dasboard component will be rendered,
    // otherwise the Home component.
    Component: Base 
    childroutes: [  
  
      { path: '/',
        getComponent: (nextState, cb) =&gt; {
  
          // Dynamically load the correct component
          if (Client.hasAccessToken()) {
            cb(null, Dashboard)
          }
          else {
            cb(null, Home)
          }
        }
      },
      // Public routes
      { path: '/login',
        component: LoginForm
      },
      ...
      // Protected routes that requires authentication
      { onEnter: redirectToLogin,
        childRoutes: [
          { path: '/users',
            getComponent: (nextState, cb) =&gt; {
              cb(null, UserTable)
            }
          },
          { path: '/users/:id',
            getComponent: (nextState, cb) =&gt; {
              cb(null, UserEdit)
            }
          },
          ....
       ]
      }
    ]
  </code></pre>