Reactjs 如何使用react路由器v4在axios拦截器内进行history.push定位?

Reactjs 如何使用react路由器v4在axios拦截器内进行history.push定位?,reactjs,push,router,react-router-v4,history,Reactjs,Push,Router,React Router V4,History,需要根据拦截器内的状态推送到特定位置,比如“/login” 有没有一种方法可以直接推到某个位置?一种快速而丑陋的方法可能是。 window.location.replace('/myUrl') 更新 解决方法可以是 /**RootComponent*/ export const myRouter = {}; @withRouter() Class RootComponent extends React.Component { constructor(props) { sup

需要根据拦截器内的状态推送到特定位置,比如“/login”


有没有一种方法可以直接推到某个位置?

一种快速而丑陋的方法可能是。 window.location.replace('/myUrl')

更新

解决方法可以是

/**RootComponent*/

export const myRouter = {};
@withRouter()
Class RootComponent extends React.Component {
    constructor(props) {
       super(props);
       myRouter = this.props.router;
    }
    render() {
      return <Provider store={store}>
            <MainComponent/>
         </Provider>
    }
}
import { myRouter } from 'RootComponent';

if (status == 401) {
    myRouter.push('/myUrl');
}

请尝试使用
this.props.history.push(“/login”)
@Jin这是什么?拦截器里面的道具?我想把它推到组件外面。在拦截器内。