如何在路由反应路由器中使用 redux 状态?

编程入门 行业动态 更新时间:2024-10-25 01:25:55
本文介绍了如何在路由反应路由器中使用 redux 状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了我的路线

<Provider store={store}> <Router history={browserHistory}> <Route path="/" component={App}> <Route path="/redux" component={redux} /> </Router> </Provider>

我的问题是当我从 redux 组件分派一个动作时,道具在 /redux 路线中改变了,但在 / 中总是初始状态.请问谁能帮帮我?

My problem is when I dispatch an action from redux component , the props changed in the /redux route but in the / always the initial state. Please who can help me ?

推荐答案

尝试使用 react-router-redux (github/reactjs/react-router-redux) 将 redux 存储与 react-router.

Try to use react-router-redux (github/reactjs/react-router-redux) to synchronise redux store with react-router.

import { browserHistory } from 'react-router'; import { syncHistoryWithStore, routerReducer } from 'react-router-redux'; import { createStore, combineReducers } from 'redux'; // Add router reducer to your store on the `routing` key const store = createStore( combineReducers({ ...reducers, routing: routerReducer }) ) // Create enhanced history that syncs navigation events with the store const history = syncHistoryWithStore(browserHistory, store); ... <Provider store={store}> <Router history={history}> <Route path="/" component={App}> <Route path="/redux" component={redux} /> </Router> </Provider>

更多推荐

如何在路由反应路由器中使用 redux 状态?

本文发布于:2023-11-25 14:14:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   器中   状态   如何在   redux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!