supasate / connected-react-router

A Redux binding for React Router v4
MIT License
4.73k stars 592 forks source link

Could not find router reducer in state tree, it must be mounted under "router": but it exists #548

Closed Lazarencjusz closed 2 years ago

Lazarencjusz commented 2 years ago

This is simple case, everything visible on attached screenshoot: Zrzut ekranu 2021-12-20 o 13 51 34

This is how I create state and reducers:

import { RouterStore } from '@fair-cms/router';
import { configureStore } from '@reduxjs/toolkit';
import { CurriedGetDefaultMiddleware } from '@reduxjs/toolkit/dist/getDefaultMiddleware';
import { routerMiddleware } from 'connected-react-router';
import { RouteName } from '../model/RouteName';
import { appHistory } from '../utils/appHistory';
import { reducer } from './reducers';

const appRouterMiddleware = routerMiddleware(appHistory);

export const store = configureStore({
  reducer,
  middleware: (getDefaultMiddleware: CurriedGetDefaultMiddleware<RouterStore<RouteName>>) => [
    ...getDefaultMiddleware({ thunk: false }),
    appRouterMiddleware,
  ],
  devTools: true,
});
import { combineReducers } from '@reduxjs/toolkit';
import { connectRouter } from 'connected-react-router';
import { appHistory } from '../utils/appHistory';

export const router = connectRouter(appHistory);

export const reducer = combineReducers({
  router,
});
import { createBrowserHistory } from 'history';

export const appHistory = createBrowserHistory();

What is going on here?

Lazarencjusz commented 2 years ago

FYI: most probably it was because module history@5, when I switch back to history@4 works ok.

Question to maintainers: do you support history@5?

JounQin commented 8 months ago

@Lazarencjusz Thanks for saving my life.