我有一个从服务器获取数据的通用操作。我正在调用各种组件的动作。我想重定向,如果响应代码为x
:从动作重定向到react-redux-router中的页面
export function commonApiCall(callUrl,data,reducer,method)
{
return dispatch =>
{
.....
....
axios({
method: callMethod,
url: ,
data: '',
headers: {
'Accept': 'application/json',
},
}).then((response) => {
if (response.code == 'x'){
// redirect I want to redirect here.
}
dispatch({
type: reducer,
});
})
.catch((error) => {
console.warn('Actions - fetchJobs - recreived error: ', error)
})
}
}
一种解决办法是在每一个component.But,我希望有一个集中式解决方案添加检查。
我想'push'是你在找什么,对不对? https://github.com/reactjs/react-router-redux#pushlocation-replacelocation-gonumber-goback-goforward – Khang