Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not find router reducer in state tree, it must be mounted under "router" #91

Closed
cikichen opened this issue Mar 7, 2019 · 8 comments

Comments

@cikichen
Copy link

cikichen commented Mar 7, 2019

{
  "private": true,
  "homepage": "https://create-react-app-redux.now.sh",
  "scripts": {
    "deploy": "now && now alias",
    "start": "react-scripts start",
    "now-start": "serve -s ./build",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "precommit": "pretty-quick --staged"
  },
  "devDependencies": {
    "prettier": "1.16.4",
    "react-scripts": "2.1.8"
  },
  "dependencies": {
    "connected-react-router": "6.3.1",
    "react": "16.8.4",
    "react-dom": "16.8.4",
    "react-redux": "6.0.1",
    "react-router": "4.3.1",
    "react-router-dom": "4.3.1",
    "redux": "4.0.1",
    "redux-thunk": "2.3.0",
    "sanitize.css": "8.0.0",
    "serve": "10.1.2",
    "history": "latest"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
@sengeezer
Copy link

Adjust your code as indicated here: https://www.npmjs.com/package/connected-react-router

This allowed me to resolve this issue. I don't entirely understand the difference or why it matters now, but it did unblock me!

@woodyjon
Copy link

Could @sengeezer or someone else be a little bit more specific on how to fix that error? I have the same error. And following above link, I cannot figure out how to adjust the code.

Thanks a lot!

@pinturic
Copy link

Did any one find the solution?

@sengeezer
Copy link

@woodyjon What I meant was, try following the module authors' how to to compare this CRA's version to their version.

Retracing my commits, what I think I did was:

  • Changed the export statement in the root reducer to the following:
export default (history) => combineReducers({
  router: connectRouter(history),
  counter,
});
  • Changed the call to createStore to:
export default createStore(
  rootReducer(history),
  initialState,
  composedEnhancers
);

I didn't implement everything as per the medium article. I already had taken a somewhat different approach, so YMMV.

@pinturic
Copy link

Well moreover I found out it was my fault. I was passing a wrong initialState...

@amir5000
Copy link

amir5000 commented Sep 1, 2019

The answer @sengeezer gave worked for me and fixed my problem.

@cikichen cikichen closed this as completed Sep 4, 2019
@progtarek
Copy link

progtarek commented Jun 27, 2020

In my case I was using history version 5.0.0, I decrease to version 4.10.1, it works fine.

ReactTraining/history#804

@xanden
Copy link

xanden commented Dec 17, 2020

The main issue is the version of the history package, with react-router-dom v5 you need to use history v4 (the latest version of which is 4.10.1) - history v5 is only compatible with react-router-dom v6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants