当用户从一个页面/路由导航到另一个页面/路由时,我正在尝试更新历史记录.但是对于我应该使用什么方法来实现这个以及为什么而感到困惑 import { browserHistory } from 'react-router'browserHis
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’)
我建议在尝试理解差异或工作原理时查看源代码.它有助于学习,也可以深入了解您正在使用的库中的最新情况:)