react-router with redux createHistory error' location'未定义的

时间:2017-02-05 15:31:14

标签: reactjs redux react-router react-router-redux

我尝试使用redux设置react和react-routers,react-redux具有以下存储初始化

import { createStore, applyMiddleware,compose } from 'redux';
import thunk from 'redux-thunk';
import {reduxReactRouter} from 'redux-router';
import { createHistory } from 'history';
import createLogger from 'redux-logger';
import rootReducer from './reducers';
import routes from './routes';

const loggerMiddleware = createLogger()


export default function configureStore(initialState) {
    let createStoreWithMiddleware;

    const logger = createLogger();

    const middleware = applyMiddleware(thunk, logger);

    createStoreWithMiddleware = compose(
        middleware,
        reduxReactRouter({routes, createHistory})
    );

    const store = createStoreWithMiddleware(createStore)(rootReducer, initialState);

    if (module.hot) {
        module.hot
            .accept('./reducers', () => {
                const nextRootReducer = require('./reducers/index');
                store.replaceReducer(nextRootReducer);
            });
    }

    return store;

}

我的应用程序是使用create-react-app创建的,在启动时我在控制台中遇到以下错误

TypeError: Cannot read property 'location' of undefined

如何调试?如何识别问题的根源?

0 个答案:

没有答案