我暂时解决了这个我认为发生在 react-router v4 上的问题。(我也有 react-router-dom),如下所示:
将组件(选择器)中的历史对象作为参数传递给动作创建者,然后在动作创建者定义中调用 history.push('/new-route')
export function register(user, history) {
// this history is the argument from the register call in the component
return function (dispatch) {
dispatch(initRequest()); // show spinner or something
return Auth.register(user)
.then(()=> {
dispatch(registerSuccess());
history.push('/new-route');
}).catch((err)=> dispatch(setErrorMessage()))
}
}
我还必须指出 createHistory 对我不起作用,我必须这样做:
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory();