question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Could not find router reducer in state tree, it must be mounted under "router" - React-Admin doesn't work with history@5.0.0

See original GitHub issue

I’m not sure if I should be posting this here, but after couple hours of headache I found the solution, so I’m here only to share, as it is probably happening to a lot of people.

As mentioned in https://marmelab.com/react-admin/Admin.html#history, I tried to use the snippet

import { createBrowserHistory as createHistory } from 'history';

const history = createHistory();

const App = () => (
    <Admin history={history}>
        ...
    </Admin>
);

I installed the history module and then began receiving the following error message:

Could not find router reducer in state tree, it must be mounted under "router".

I eventually stumbled upon this thread and found a life-saving suggestion

https://github.com/supasate/connected-react-router/issues/312

No, just lib history update v5.0.0, i decrease verion 4.10.1, it’s work ok ReactTraining/history#804

I did as he suggested and my App came back to life.

I didn’t have time to dig too deep into it, but for what I realized, there’s probably a mismatch between the versions of react-router-dom and the history module. But I have zero confidence that’s really the case.

So I really don’t know what to do with the information.

I’m using the latest and greatest version (3.9.5) of react-admin, of which I’m becoming an evangelist. (Nice work, guys!). The project was created just two days ago. I’ve have been using RA for the last year with never having a single problem up until now.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
altenorjrcommented, Oct 29, 2020

@fzaninotto I think while it isn’t fixed, this info could be be included in the docs, under the history prop section in the <Admin /> component docs.

Apart from actually fixing it, I guess maybe setting the history module as a peerDependency and locking it to the last known working version (4.10.1) could potentially do the trick. Or at least work as a warning or a guide.

0reactions
magnatticcommented, Oct 28, 2021

I am facing this same errror message in a project running yarn 3 in pnp mode. I am not even using history directly.

I have storybook in the same workspace that uses a history >5, but that shouldn’t really affect anything as yarn should be isolating the subdependencies, right?

yarn why history ├─ @storybook/router@npm:6.4.0-beta.22 │ └─ history@npm:5.0.1 (via npm:^5.0.1) │ ├─ @storybook/router@npm:6.4.0-beta.22 [6c9a3] │ └─ history@npm:5.0.1 (via npm:^5.0.1) │ ├─ @storybook/router@npm:6.4.0-beta.22 [dfecf] │ └─ history@npm:5.0.1 (via npm:^5.0.1) │ ├─ react-router-dom@npm:5.3.0 │ └─ history@npm:4.10.1 (via npm:^4.9.0) │ ├─ react-router-dom@npm:5.3.0 [0e836] │ └─ history@npm:4.10.1 (via npm:^4.9.0) │ ├─ react-router@npm:5.2.1 │ └─ history@npm:4.10.1 (via npm:^4.9.0) │ └─ react-router@npm:5.2.1 [0e836] └─ history@npm:4.10.1 (via npm:^4.9.0)

Any idea what the source could be and how to fix it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find router reducer in state tree, it must be mounted ...
I am new to React.js and was setting up base project at that I was getting one issue that my ...
Read more >
Error: Could not find router reducer in state tree, it must be ...
Hello there! I was trying to introduce google auth to my react-redux app for over a week and I was finally able to...
Read more >
Could not find router reducer in state tree, it must be mounted ...
I ran into the same issue. I forgot to give the history as a parameter to my rootReducer, in my store initialization. const...
Read more >
Could not find router reducer in state tree, it must be ... - Reddit
The above error occurred in the component: in ConnectedRouter in ConnectedRouterWithContext in ConnectFunction in Provider I am stuck in a ...
Read more >
React-admin - Upgrading to v4 - Marmelab
If you use TypeScript, the migration will be much faster. MUI v5. React-admin v4 uses MUI (Material-UI) v5. The MUI team has written...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found