gpt4 book ai didi

reactjs - Redux 路由器未捕获类型错误 : createHistory is not a function

转载 作者:行者123 更新时间:2023-12-02 04:03:10 25 4
gpt4 key购买 nike

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/createBrowserHistory';

错误变成Uncaught TypeError: History.getCurrentLocation is not a function

想法?

最佳答案

我通过在 package.json 中指定历史版本 3 解决了这个问题

"history": "^3.0.0",

react-router 3.0.0 将history 3.0.0指定为依赖项,但由于某种原因,它没有添加到node_modules中。但将其显式添加到您自己的 package.json 中解决了我的问题。

我认为react-router 3.0.0尚不兼容history v4。我不确定为什么 npm 没有观察到 React-router v3.0.0 package.json 中的依赖关系

关于reactjs - Redux 路由器未捕获类型错误 : createHistory is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40908571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com