在操作 redux 后反应路由器重定向 [英] React router redirect after action redux
问题描述
我正在使用 react-redux
和 react-router
.我需要在分派操作后重定向.
I'm using react-redux
and react-router
. I need to redirect after an action is dispatched.
例如:我注册了几步.行动后:
For example: I have registration a few steps. And after action:
function registerStep1Success(object) {
return {
type: REGISTER_STEP1_SUCCESS,
status: object.status
};
}
我想重定向到带有 registrationStep2 的页面.我该怎么做?
I want to redirect to page with registrationStep2. How can I do this?
附言在历史浏览器 '/registrationStep2' 中没有被访问过.此页面只有在结果注册成功后才会出现Step1页面.
p.s. In history browser '/registrationStep2' has not been visited. This page appears only after successful result registrationStep1 page.
推荐答案
使用 React Router 2+,无论您在何处调度 action,都可以调用 browserHistory.push()
(或 hashHistory.push()
如果这是你使用的):
With React Router 2+, wherever you dispatch the action, you can call browserHistory.push()
(or hashHistory.push()
if that’s what you use):
import { browserHistory } from 'react-router'
// ...
this.props.dispatch(registerStep1Success())
browserHistory.push('/registrationStep2')
如果您使用异步操作创建器,您也可以这样做.
You can do this from async action creators too if that is what you use.
这篇关于在操作 redux 后反应路由器重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!