title: Redirect React Router from function
body: <p>I am creating a React application using create-react-app, react-redux, react-thunk, react-router.</p>
  
  <p>I am setting a localstorage variable "current_user" after authenticating so that I can setup my Restricted Routers.</p>
  
  <p>I am using Axios to make the ajax requests, and In my initial index.js file I have setup a global Axios Interceptor so that if any ajax call returns 401, it automatically clears the local storage "current_user". I would like it to also redirect to /Login.</p>
  
  <p>I'm able to do this the old fashioned way (ie window.location) however, is there a way to set this global function to redirect from anywhere in the application to the login page? </p>
  
  <p>The global interceptor:</p>
  
  <p>index.js</p>
  
  <pre><code>import "materialize-css/dist/css/materialize.min.css";
  import "jquery/dist/jquery.min.js";
  import "materialize-css/dist/js/materialize.min.js";
  import React from "react";
  import ReactDOM from "react-dom";
  import { Provider } from "react-redux";
  import { createStore, applyMiddleware } from "redux";
  import reduxThunk from 'redux-thunk';
  import axios from "axios";
  
  import App from "./components/App";
  import reducers from './reducers';
  
  const store = createStore(reducers, {}, applyMiddleware(reduxThunk));
  
  axios.interceptors.response.use(undefined, function (error) {
    if(error.response.status === 401) {    //Setup Global Config
      localStorage.setItem('current_user', null);
     //Would like to redirect to /Login here
    }
  });
  
  ReactDOM.render(
    &lt;Provider store={store}&gt;
      &lt;App /&gt;
    &lt;/Provider&gt;,
    document.querySelector("#root")
  );
  </code></pre>