根据the documentation,我应该可以通过致电LOCATION_CHANGE
来发起push('/with/the/path')
事件。来自docs的示例:
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'))
然而,这看起来就像是我打电话给我而得到这个(这看起来不像是在做什么):
我缺少什么?
答案 0 :(得分: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
的位。
希望这有帮助。