React-admin: Error: Could not find router reducer in state tree, it must be mounted under "router" - React-Admin doesn't work with [email protected]

Created on 28 Oct 2020  路  4Comments  路  Source: marmelab/react-admin

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

````javascript import * as React from "react";
import { createBrowserHistory as createHistory } from 'history';

const history = createHistory();

const App = () => (
...

);
````

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.

bug

Most helpful comment

@fzaninotto I think while it isn't fixed, this info could be be included in the docs, under the history prop section in the 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.

All 4 comments

I'm having the same problem.

Thanks @altenorjr :)

I'd love to be able to detect the version of history passed to react-admin, and throw an explicit warning if it's a 5.0, but unfortunately I didn't find anything in the history public API allowing for that.

If anyone knows a way, please chime in!

I'm reopening this issue as it's something that will bite more devs.

@fzaninotto I think while it isn't fixed, this info could be be included in the docs, under the history prop section in the 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yangjiamu picture yangjiamu  路  3Comments

kikill95 picture kikill95  路  3Comments

pixelscripter picture pixelscripter  路  3Comments

ilaif picture ilaif  路  3Comments

9747749366 picture 9747749366  路  3Comments