2

根据文档,我应该能够LOCATION_CHANGE通过调用来触发事件push('/with/the/path')。来自文档的示例:

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 时我得到了这个(看起来它没有做任何事情):

在此处输入图像描述

我错过了什么?

4

1 回答 1

2

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

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 之后注意一点。

希望这可以帮助。

于 2016-07-11T15:01:40.450 回答