2 回答

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個贊
v4需不需要看個人項目需求,在react-router-redux
文檔中有這么一些說明:
如果要使用react-router-redux
也是可以的,可以參考這個文檔說明來使用:

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個贊
是的。而且在react-router
V3也可以不用react-router-redux
。這里我說下V3版本如何同步histroy
到store
。不BB,直接上代碼:
import { browserHistory } from 'react-router'
import { createStore } from 'redux'
// action
function locationChange (location = '/') {
return {
type : 'LOCATION_CHANGE',
payload : location
}
}
// reducer
const initialState = browserHistory.getCurrentLocation()
function locationReducer (state = initialState, action) {
return action.type === 'LOCATION_CHANGE'
? action.payload
: state
}
// store
const store = createStore(locationReducer)
const updateLocation = ({ dispatch }) => {
return (nextLocation) => dispatch(locationChange(nextLocation))
}
//綁定browserHistory,取消綁定執(zhí)行store.unsubscribeHistory()
store.unsubscribeHistory = browserHistory.listen(updateLocation(store))
添加回答
舉報