加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – react-router-redux的“push”方法和react-router的

发布时间:2020-12-15 16:18:25 所属栏目:百科 来源:网络整理
导读:当用户从一个页面/路由导航到另一个页面/路由时,我正在尝试更新历史记录.但是对于我应该使用什么方法来实现这个以及为什么而感到困惑 import { browserHistory } from 'react-router'browserHistory.push('/bag') 要么 import { routerMiddleware,push } fro
当用户从一个页面/路由导航到另一个页面/路由时,我正在尝试更新历史记录.但是对于我应该使用什么方法来实现这个以及为什么而感到困惑

import { browserHistory } from 'react-router'
browserHistory.push('/bag')

要么

import { routerMiddleware,push } from 'react-router-redux'
const middleware = routerMiddleware(browserHistory)
const store = createStore(
  reducers,applyMiddleware(middleware)
)

store.dispatch(push('/bag'))

请帮忙.提前致谢 :)

解决方法

基本上,如果您了解使用redux和react-router-redux的原因:

store.dispatch(push(‘/ bug’))将导航状态保持在商店中,推送并导航到路径

同时

browserHistory.push(‘/ bag’)只是推送并导航到路线.

From the source code itself

/**
* These actions correspond to the history API.
* The associated
routerMiddleware will capture these events before they get to
* your
reducer and reissue them as the matching function on your history. */

export const push = updateLocation(‘push’)

我建议在尝试理解差异或工作原理时查看源代码.它有助于学习,也可以深入了解您正在使用的库中的最新情况:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读