如何在reactjs应用程序中从axios拦截器重定向?

如何在reactjs应用程序中从axios拦截器重定向?,reactjs,react-router-redux,axios,Reactjs,React Router Redux,Axios,我试图检查每个axios请求是否在非公共路径的头中存在令牌。我想让用户登录页面,以防找不到令牌。 但这是在reactjs应用程序中。怎样才能做到这一点 axios.interceptors.request.use(function (config) { //If the header does not contain the token and the url not public, redirect to login var accessToken = null; if(sessio

我试图检查每个axios请求是否在非公共路径的头中存在令牌。我想让用户登录页面,以防找不到令牌。 但这是在reactjs应用程序中。怎样才能做到这一点

axios.interceptors.request.use(function (config) {
 //If the header does not contain the token and the url not public, redirect to login  
 var accessToken = null;
 if(sessionStorage.getItem('currentUserString')){
  accessToken =  'bearer '+JSON.parse(sessionStorage.getItem('currentUserString')).tokenDetails.accessToken;
 }

 var configURL = config.url;
 //if token is found add it to the header
 if (accessToken) {
   if (config.method !== 'OPTIONS') {
          config.headers.authorization = accessToken;
   }
 }
 //otherwise if the request is not for login page/auth service/home redirect to login page
 else if(!isNotOpenPath(config.url)){

   //we may want to store current path in the cookies. This can be retrieved after login is successful
   //WHAT TO DO HERE TO TAKE USER TO LOGIN PAGE IN THE REACT JS APP????
  }    
}
如何向react应用程序发送信号,特别是我们这里没有调度。 我能用它吗
document.location.href='\login'

我认为在应用程序中设置路由的方法是使用React路由器。。。 然后你可以试试这个


为什么不使用window.location='loginPath'?好的。但这将是一种方法。正确的?没有特定的方式存在?browserHistory很有意义,也很有效:)谢谢!