2016-07-08 5 views
2

the documentation에 따르면 LOCATION_CHANGE 이벤트를 호출하려면 push('/with/the/path')을 호출해야합니다. 문서에서 예제 :react-router-redux에 대해 LOCATION_CHANGE 이벤트를 발생시키는 방법은 무엇입니까?

enter image description here

어떻게 생각 :

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

'푸시 (push)'헬퍼 메소드는이 목적을 위해 정확하게 사용됩니다. 수동으로 실행하려는 유스 케이스는 무엇입니까? 푸시 메소드로 포장 된 내부 구조가있을 수 있습니다. 그렇지 않으면 호출 할 수 없습니다. –

+0

'syncHistoryWithStore' 했습니까? – xiaofan2406

+0

@MarioTacke 앱의 다른 부분으로 리디렉션하려고합니다. (예 : '/ 프로필') – drewwyatt

답변

2

기록을 저장소와 동기화해야합니다. 비트가에 대한 syncHistoryWithStore 후에는 저장소를 만들

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

주의 사항 : 다음은 예제 설정이다.

희망이 도움이됩니다.