在状态树中找不到路由器还原器,必须在“路由器”下安装它。
我正在使用这些版本
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-router-dom": "^5.2.0"
"connected-react-router": "^6.8.0"
"history": "4.10.1"
导出const browserhistory = create browserhistory({{ Basename:“/清除授权” })
我遇到此错误在状态树中找不到路由器还原器,必须将其安装在“路由器”
reducers.js
export default (history) => {
const appReducer = (asyncReducer) => {
return combineReducers({
notifications,
router: connectRouter(history),
...asyncReducer
})
}
const rootReducer = (state, action) => appReducer(state, action)
return rootReducer
}
store.js
import { createBrowserHistory } from 'history'
export const history = createBrowserHistory({
basename: '/clearance'
})
const middleware = [routerMiddleware(history), sagaMiddleware, notifications]
const configureStore = (initialState) => {
const store = createStore(
createReducer(history),
initialState,
compose(
applyMiddleware(...middleware),
getReduxDevTools(process.env.NODE_ENV === 'development')
)
)
store.asyncReducers = {}
store.runSaga = sagaMiddleware.run
store.close = () => store.dispatch(END)
return store
}
export default configureStore
app.js下
import configureStore, { history } from './redux/store'
import { ConnectedRouter } from 'connected-react-router'
<Provider store={store}>
<ConnectedRouter history={history}>
<Frame handleScrolling={false}>
</Frame>
</ConnectedRouter>
</Provider>
I am using these versions
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-router-dom": "^5.2.0"
"connected-react-router": "^6.8.0"
"history": "4.10.1"
export const browserHistory = createBrowserHistory({
basename: '/clearance-authorization'
})
i am getting this Error Could not find router reducer in state tree, it must be mounted under "router"
reducers.js
export default (history) => {
const appReducer = (asyncReducer) => {
return combineReducers({
notifications,
router: connectRouter(history),
...asyncReducer
})
}
const rootReducer = (state, action) => appReducer(state, action)
return rootReducer
}
store.js
import { createBrowserHistory } from 'history'
export const history = createBrowserHistory({
basename: '/clearance'
})
const middleware = [routerMiddleware(history), sagaMiddleware, notifications]
const configureStore = (initialState) => {
const store = createStore(
createReducer(history),
initialState,
compose(
applyMiddleware(...middleware),
getReduxDevTools(process.env.NODE_ENV === 'development')
)
)
store.asyncReducers = {}
store.runSaga = sagaMiddleware.run
store.close = () => store.dispatch(END)
return store
}
export default configureStore
App.js
import configureStore, { history } from './redux/store'
import { ConnectedRouter } from 'connected-react-router'
<Provider store={store}>
<ConnectedRouter history={history}>
<Frame handleScrolling={false}>
</Frame>
</ConnectedRouter>
</Provider>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的描述和错误中出发
,似乎您没有将连接的路由器添加到根还原器中。
解决方案
导入
ConnectRouter
函数,并使用路由器
键创建root还原器,然后传递历史记录
对象。 Redux没有匹配的还原器,或者特别是连接的反应 - 曲线
选择器正在尝试从不存在的状态中进行选择。from docs :
...
导入您的历史记录对象和自定义
createrootredeDucer
在创建Redux商店时使用。请按照连接的反应路由器
文档进行细节。例子:
Issue
From your description and error it seems you've not added the connected router to your root reducer.
Solution
Import
connectRouter
function and create the root reducer with arouter
key and pass thehistory
object. Redux doesn't have a matching reducer, or specifically theconnected-react-router
selectors are attempting to select from non-existent state.Example from docs:
...
Import your history object and custom
createRootReducer
for use when creating your Redux store. Follow the rest of theconnected-react-router
docs for specifics.Example:
更改了还原器中的代码
reducers.js
changed the code in reducers
reducers.js