drewwyatt
drewwyatt

Reputation: 6027

How do I fire a LOCATION_CHANGE event for react-router-redux?

According to the documentation I should be able to fire a LOCATION_CHANGE event by calling push('/with/the/path'). Example from 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'))

However, this looks like when I call push I'm getting this (which doesn't look like it's doing anything):

enter image description here

What am I missing?

Upvotes: 2

Views: 2747

Answers (1)

Mario Tacke
Mario Tacke

Reputation: 5488

Make sure to sync your history with your store. The following is an example setup:

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'))

Notice the bit about syncHistoryWithStore after you create the store.

Hope this helps.

Upvotes: 2

Related Questions