簡體   English   中英

Redux Router Uncaught TypeError:createHistory不是函數

[英]Redux Router Uncaught TypeError: createHistory is not a function

Redux路由器版本^ 2.1.2

react-router版本: "react-router": "^3.0.0" ,歷史記錄版本: "history": "^4.3.0"

重現步驟

    import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import { Router, browserHistory } from 'react-router';
import { reduxReactRouter, routerStateReducer, ReduxRouter } from 'redux-router';
import reduxThunk from 'redux-thunk';
import { createHistory } from 'history';

import rootReducer from './core/rootReducer';
import routes from './core/routes';

import * as axios from './utils/axios.js';

import { AUTH_USER } from './authentication/types';

const store = compose(applyMiddleware(reduxThunk),
    reduxReactRouter({ routes, createHistory })
)(createStore)(rootReducer);

const token = localStorage.getItem('token');

if (token) {
    store.dispatch({ type: AUTH_USER });
}

ReactDOM.render(
    <Provider store={store}>
        <ReduxRouter>

            {routes}

        </ReduxRouter>
    </Provider>
    , document.querySelector('.main')
);

它返回錯誤index.js:34416 Uncaught TypeError: createHistory is not a function(…)

有什么辦法嗎?


import { createHistory } from 'history';更改import { createHistory } from 'history';之后import { createHistory } from 'history'; import createHistory from 'history/createBrowserHistory';

該錯誤變為Uncaught TypeError: history.getCurrentLocation is not a function

有什么想法嗎?

我通過在package.json中指定歷史記錄的第3版來解決此問題

"history": "^3.0.0",

react-router 3.0.0將歷史記錄3.0.0指定為依賴關系,但是由於某種原因,它沒有添加到node_modules中。 但是將其顯式添加到您自己的package.json中可以解決此問題。

我認為react-router 3.0.0尚未與歷史記錄v4兼容。 我不確定為什么npm不遵守react-router v3.0.0 package.json中的依賴關系

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM