connectedRouter Error: Could not find router reducer in state tree, it must be mounted under “router”

后端 未结 6 1554
轮回少年
轮回少年 2021-01-01 15:09

I am new to React.js and was setting up base project at that I was getting one issue that my routing got changed but component doesn\'t load. After googling I found that I n

相关标签:
6条回答
  • 2021-01-01 15:34

    For the sake of helping future souls with this issue, it turns out that according to the linked github discussions, that version 5.0 of the history package is causing the issue and downgrading to version 4.10.1 solves the problem for me.

    npm install history@4.10.1
    

    https://github.com/ReactTraining/history/issues/803

    https://github.com/ReactTraining/history/issues/804

    0 讨论(0)
  • 2021-01-01 15:38

    You have forgotten :

    router: connectRouter(history), 

    in your combineReducers()

    0 讨论(0)
  • 2021-01-01 15:45

    If you use immutable you should import ConnectedRouter from 'connected-react-router/immutable'.

    0 讨论(0)
  • 2021-01-01 15:57

    I ran into the same issue. I forgot to give the history as a parameter to my rootReducer, in my store initialization.

    const store = createStore(
      rootReducer(history), // <-- HERE
      {},
      ...
    )
    
    0 讨论(0)
  • 2021-01-01 15:59

    Add router in your reducer with using connectRouter and history

    Refer this link

    https://www.npmjs.com/package/connected-react-router

    import { connectRouter } from 'connected-react-router'
    const rootReducer = combineReducers({
      login: loginReducer,
      router: connectRouter(history),
    });
    
    0 讨论(0)
  • 2021-01-01 15:59

    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.

    0 讨论(0)
提交回复
热议问题