React Redux History错误 - TypeError:(0,_history2.default)不是函数

时间:2016-01-27 20:48:43

标签: javascript reactjs history redux

历史2.0.0-rc2

跟随this example逐字和:

import { createHistory }  from 'history';
import { applyMiddleware, compose, createStore } from 'redux';
import { syncHistory } from 'react-router-redux';

const history = createHistory(); //<-- ***THIS LINE IS FAILING!!!***
const routingMiddleware = syncHistory(history);

...使用TypeError: (0 , _history2.default) is not a function创建历史失败。我试过没有{}并尝试从createBrowserHistory导入它也有相同的结果。我错过了什么?我开了一个但反对历史,但是他们说我们不会查看bug,所以请在stackoverflow上发帖。

2 个答案:

答案 0 :(得分:1)

好的 - 显然现在必须从react-router而不是react-router-redux(以前称为redux-simple-router)调用push,replace等。无论如何,自从那些工作以来,我将回到它们的1.x版本。

@Brandon - 仅供参考 - 我确实拥有正确的历史版本。感谢您的建议

答案 1 :(得分:0)

history的npm包看起来有问题。

尝试运行npm ls|grep history以查看您安装的版本。确保您确实使用的是最新版本(2.0.0-rc2)。

您也可以尝试删除node_modules/history并重新安装。