【发布时间】:2017-02-16 22:57:55
【问题描述】:
我正在尝试将 push 方法从 redux-router 添加到操作中。
当我启动操作时,推送接收有效负载中的对象,但不要更改页面。
enter image description here
actions/index.js
import { push } from 'redux-router';
export const actions = {};
actions.goTo = () => {
return (dispatch) => {
dispatch(push('/staff'));
};
};
但是如果我不是从动作中初始化push,而是直接在组件中它可以正常工作。
我的组件/index.js
import { push } from 'redux-router';
import { connect } from 'react-redux';
@connect((state) => ({}))
export default class MyComponent extends Component {
constructor (props) {
super(props);
this._goTo = ::this._goTo;
}
_goTo (event) {
event.preventDefault();
const { dispatch } = this.props;
dispatch(push('/staff'));
}
render () {
return (
<section>
<button onClick = { this._goTo }>from component</button>
</section>
);
}
}
【问题讨论】:
标签: javascript reactjs redux redux-router