title: Redirect using react-router in redux middleware
body: <p>I've created a middleware that checks if a request returns an invalid access response. If the status is a 401, I want to redirect the user to the login page</p>
  
  <p>Here's the middleware code</p>
  
  <pre><code>import React from 'react';
  import { push, replace } from 'react-router-redux';
  
  const auth_check = ({ getState }) =&gt;  {
    return (next) =&gt; (action) =&gt; {
      if(action.payload != undefined &amp;&amp; action.payload.status==401){
          push('login');
          console.log('session expired'); 
      }
      // Call the next dispatch method in the middleware chain.
      let returnValue = next(action);
  
      return returnValue
    }
  }
  
  export default auth_check;
  </code></pre>
  
  <p>Including it in index.js</p>
  
  <pre><code>...
  
  const store = createStore(reducers, undefined, 
              compose(
                  applyMiddleware(promise,auth_check)
                  )
              );
  const history = syncHistoryWithStore(browserHistory, store);
  
  ReactDOM.render(
    &lt;Provider store={store}&gt;
      &lt;Router history={history} routes={routes} /&gt;
    &lt;/Provider&gt;
    , document.querySelector('.app'));
  </code></pre>
  
  <p>The push method does not redirect the page. I am sure that the code goes through that section since the log is showing</p>