react router redux 簡單例子

2021-08-14 04:00:47 字數 2186 閱讀 8202

reducer與按需載入元件的時候,一併載入對應的state,具體流程就不多說了,看**!

import  from 'redux'

import from 'react-router-redux'

export

const makerootreducer = asyncreducers=> )

}export

const

injectreducer = (store, ) =>

}

import from 'react-router-redux'

import thunkmiddleware from 'redux-thunk'

import reducer, from './reducer'

export

default

(initialstate = {}, history) =>

import react,  from 'react'

import from 'react-router'

const moduleroute = require.context('../view', true, /router$/) //獲取view檢視下,所有router檔案

const router = store=> )

}'*' to='/' />

}export

default router

import reactdom from 'react-dom'

import from 'react-router'

import react from 'react'

import from 'react-redux'

import from 'react-router-redux'

import createstore from '...上面的store'

import router from '...上面的router'

const store = createstore({}, hashhistory);

store.asyncreducers = {};

const history = synchistorywithstore(hashhistory, store);

reactdom.render((

), document.getelementbyid("root"))

在view層級下建立乙個test資料夾來編輯一下流程

在test/ index.jsx 中簡單編輯下

import react,  from 'react'

import from 'react-redux'

class

test

extends

component = this.props;

return

}}const mapstatetoprops = state =>

}const mapdispathtoprops = dispatch =>

}export default connect(mapstatetoprops, mapdispathtoprops)(test);

reducer

const initstate = 

export

default

(state = initstate, action) =>

router

import  from 'react-router'

import from '...最上面定義的reducer'

export

default store=> );

cb(null, module.default);})}

}/>

}

執行,在未載入該頁面之前,store.state = ;

進入test頁面的時候, store.state = }

react router redux實際操作

react router學習 import react,from react import stepone from stepone import steptwo from steptwo import stepthree from stepthree import from antd import...

cokies簡單用例

從提交的html表單中獲取,使用者名稱 string username request.getparameter username 以 username username 值 對 建立乙個cookie cookie theusername new cookie username username r...

簡單的單例

singleton 單例模式,保證乙個類僅有乙個例項,並提供乙個訪問它的全域性訪問點 乙個簡單的單例模式 class singleton public static singleton getsingleton return singleton 客戶端 public static void main...