Javascript 如何为react router redux触发位置更改事件?

Javascript 如何为react router redux触发位置更改事件?,javascript,redux,react-router,react-router-redux,Javascript,Redux,React Router,React Router Redux,据我所知,我应该能够通过调用push('/with/the/path')触发LOCATION\u CHANGE事件。文档中的示例: import { routerMiddleware, push } from 'react-router-redux' // Apply the middleware to the store const middleware = routerMiddleware(browserHistory) const store = createStore( reduc

据我所知,我应该能够通过调用
push('/with/the/path')
触发
LOCATION\u CHANGE
事件。文档中的示例:

import { routerMiddleware, push } from 'react-router-redux'

// Apply the middleware to the store
const middleware = routerMiddleware(browserHistory)
const store = createStore(
  reducers,
  applyMiddleware(middleware)
)

// Dispatch from anywhere like normal.
store.dispatch(push('/foo'))
然而,当我调用push时,我得到了这个结果(看起来它什么都没做):


我遗漏了什么?

请确保将您的历史记录与您的店铺同步。以下是一个示例设置:

import { routerMiddleware, syncHistoryWithStore, push } from 'react-router-redux'

// Apply the middleware to the store
const router = routerMiddleware(browserHistory)
const store = createStore(
  reducers,
  applyMiddleware(router)
)
const history = syncHistoryWithStore(browserHistory, store)

// Dispatch from anywhere like normal.
store.dispatch(push('/foo'))
请注意,在创建存储之后,有关
syncHistoryWithStore
的部分


希望这有帮助。

推送helper方法正是为了这个目的。您尝试手动启动它的用例是什么?可能有一些内部文件被push方法包装,您无法以其他方式调用。您是否
syncHistoryWithStore
?@MarioTacke我正在尝试重定向到应用程序的另一部分。(即“/profile”)@xiaofan2406我做到了:(@MarioTacke我忘了应用RouterMiddle软件。:s如果你要发布答案,我会将其标记为已接受。