reduxでreact-router-reduxジャンプルーティングを使用する


1.インストール
npm install --save history
npm install --save react-router-redux

2.パッケージ
import {createStore, compose, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducer';
import {routerMiddleware} from 'react-router-redux';

let createHistory = require('history').createHashHistory;
let history = createHistory();   //    history
let routerWare = routerMiddleware(history);

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducer, composeEnhancers(
    applyMiddleware(thunk, routerWare)
));

export default store;

3.使用
import {push} from 'react-router-redux';

//     actionCreators.js  
//   
export const loginSystem = (params) => async (dispatch) => {
    try {
        dispatch(changeLoading(true));
        let {data} = await loginAsync(params); 
        if (data['msgCode'] === 0) {
            dispatch(changeUserName(true, params['username'])); 
            dispatch(push('/home')); //    home  ,        ,   
        } else {
            Toast.info(data['message'], 2);
        }
        dispatch(changeLoading(false));
    } catch (error) {
        Toast.info(error, 2);
    }
}