我想在登录后在容器中使用"LoginPage“(智能组件)重定向。如下所示:
handleSubmit(username, pass, nextPath) {
function redirect() {
this.props.pushState(null, nextPath);
}
this.props.login(username, pass, redirect); //action from LoginAcitons
}来自哑组件的用户名和密码已到达。
智能组件连接
function mapStateToProps(state) {
return {
user: state.app.user
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(LoginActions, dispatch)
}如何从redux-router添加pushState?还是我走错路了?
export default connect(mapStateToProps, {pushState})(LoginPage); //works, but haven't actions
export default connect(mapStateToProps, mapDispatchToProps)(LoginPage); //works, but haven't pushState
export default connect(mapStateToProps, mapDispatchToProps, {pushState})(LoginPage); //Uncaught TypeError: finalMergeProps is not a function发布于 2015-12-24 17:46:19
function mapStateToProps(state) {
return {
user: state.app.user
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(LoginActions, dispatch),
routerActions: bindActionCreators({pushState}, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LoginPage);发布于 2018-01-19 22:08:08
简单的骨架:
import React from 'react';
import ReactDOM from 'react-dom'
import { createStore,applyMiddleware, combineReducers } from 'redux'
import { connect, Provider } from 'react-redux'
import thunk from 'redux-thunk'
import logger from 'redux-logger'
import View from './view';
import {playListReducer, artistReducers} from './reducers'
/*create rootReducer*/
const rootReducer = combineReducers({
playlist: playListReducer,
artist: artistReducers
})
/* create store */
let store = createStore(rootReducer,applyMiddleware(logger ,thunk));
/* connect view and store */
const App = connect(
state => ({
//same key as combineReducers
playlist:state.playlist,
artist:state.artist
}),
dispatch => ({
})
)(View);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider> ,
document.getElementById('wrapper'));https://stackoverflow.com/questions/34450396
复制相似问题