首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在状态树中找不到路由器减速器,必须安装在“路由器”下。

在状态树中找不到路由器减速器,必须安装在“路由器”下。
EN

Stack Overflow用户
提问于 2020-06-24 11:16:12
回答 1查看 3K关注 0票数 2

路由器正常工作。但是,如果我添加了<Redirect>或来自<Link>的调用,就会有以下异常:

未在状态树中找到路由器减速器,必须安装在“路由器”下。

rootReducer.js:

代码语言:javascript
复制
    import { combineReducers } from 'redux';
    import { connectRouter } from 'connected-react-router';
    import counterReducer from './Counter/counter.reducer';
    import sidebarReducer from './Sidebar/sidebar.reducer';

    export default (history) => combineReducers({
        router: connectRouter(history),
        counter: counterReducer,
        sidebar: sidebarReducer,
    });

store.js:

代码语言:javascript
复制
    import { createBrowserHistory } from 'history';
    import { applyMiddleware, compose, createStore } from 'redux';
    import { routerMiddleware } from 'connected-react-router';
    import createRootReducer from './rootReducer';

    export const history = createBrowserHistory();

    export default function configureStore(preloadedState) {
        const composeEnhancer = compose
        const store = createStore(
            createRootReducer(history),
            preloadedState,
            composeEnhancer(
                applyMiddleware(
                routerMiddleware(history),
            ),
        ),
    );

    if (module.hot) {
        module.hot.accept('./rootReducer', () => {
            store.replaceReducer(createRootReducer(history));
        });
    }

    console.log(store.getState());

    return store;
    }
EN

回答 1

Stack Overflow用户

发布于 2020-07-16 21:41:28

检查历史文档。如果您使用的是@5.x.x,那么您应该使用history@4.10.1,因为最新版本的历史记录(v5)只适用于@6.x.x。

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62553781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档