如何为 react-router-redux 触发 LOCATION_CHANGE 事件?
How do I fire a LOCATION_CHANGE event for react-router-redux?
根据 the documentation,我应该可以通过调用 push('/with/the/path')
来触发 LOCATION_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
在您创建商店后。
希望对您有所帮助。
根据 the documentation,我应该可以通过调用 push('/with/the/path')
来触发 LOCATION_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
在您创建商店后。
希望对您有所帮助。