第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

react-router-redux在react-router成為4.0后是不是不需要了

react-router-redux在react-router成為4.0后是不是不需要了

紅糖糍粑 2018-07-17 09:23:11
本來在項目打算使用如下的配置,本人通過一些教程中看到了如果想要用react router和redux結(jié)合使用的話需要如下的依賴,但是當(dāng)我從官網(wǎng)的create-creact-app搭建的一個項目中發(fā)現(xiàn)了browserHistory這個依賴已經(jīng)沒有了。然后同樣的有一個react-router-dom中有一個BrowserRouter這個組件是可以實(shí)現(xiàn)相同的,是不是不需要react-router-redux進(jìn)行router和store同步了啊import { Router, Route, browserHistory } from 'react-router' import { syncHistoryWithStore } from 'react-router-redux';
查看完整描述

2 回答

?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個贊

v4需不需要看個人項目需求,在react-router-redux文檔中有這么一些說明:

https://img3.sycdn.imooc.com/5b52d8a40001297308000211.jpg

如果要使用react-router-redux也是可以的,可以參考這個文檔說明來使用:

https://img3.sycdn.imooc.com/5b52d8b00001c19007740800.jpg


查看完整回答
反對 回復(fù) 2018-07-21
?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個贊

是的。而且在react-router V3也可以不用react-router-redux。這里我說下V3版本如何同步histroystore。不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))


查看完整回答
反對 回復(fù) 2018-07-21
  • 2 回答
  • 0 關(guān)注
  • 1060 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號