升级到React 16,react-router-redux不起作用

时间:2017-10-10 04:56:05

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

我最近将React版本升级到16版,从那时起,react-router-redux(我正在使用Redux)似乎不起作用。我的代码太大了,无法在此粘贴。但是,它看起来与https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux非常相似。

这就是我的代码:

//Combine the Epics
const rootEpic = combineEpics(
    storeEpic,
    shoppingListEpic,
    landingEpic,
    incrementalSearchEpic,
    completedSavedShoppingEpic
);

const epicMiddleware = createEpicMiddleware(rootEpic, {
    dependencies: {
        incrementalSearchService: IncrementalSearchServiceMock
    }
});

//Combine the reducers
const reducer = combineReducers({
    syncSpaceReducer,
    routing: routerReducer
});

const transitionHistory = createHistory();

const enhancer = compose(
    applyMiddleware(thunkMiddleware, epicMiddleware),
    handleTransitions(transitionHistory),
    DevTools.instrument()
);

const store = createStore(reducer, enhancer);
const history = syncHistoryWithStore(browserHistory, store);

render(
    <Provider store={store}>
        <div>
            <Router history={history} routes={routes} />
            <DevTools />
        </div>
    </Provider>,
    document.getElementById('syncspace')
);

我该如何解决?

3 个答案:

答案 0 :(得分:0)

尝试卸载并再次安装此软件包,它们一起为我工作:

    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.0.14",
    "redux": "^3.7.2",
    "redux-form": "^7.0.4",

答案 1 :(得分:0)

与React 16兼容的react-router-redux版本尚未投入生产。您可以使用他们的alpha版本。他们在react-router内移动了回购。

如其页面所述,运行npm install --save react-router-redux@next可以解决您的问题。

答案 2 :(得分:0)

react-router-redux已弃用。而是使用connected-react-routerenter image description here