store.js:
import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { reducer as firstReducer } from '../views/First/_index.js';
import { reducer as twoReducer } from '../views/TwoRedux/_index.js';
// import {reducer as ajaxReducer} from '../views/5-19/index'
import { reducer as downupReducer } from '../views/Downup/_index.js'
import { reducer as zero } from '../views/zero/store'
import { reducer as url } from '../views/url/_index.js'
const reducer = combineReducers({
first: firstReducer,
two: twoReducer,
// three:ajaxReducer,
downup: downupReducer,
zero: zero,
url: url
// remove:removeReducer,
// edit:editReducer,
})
function newJson(str){
if(str){
var json = (new Function('return' + str))();
return json
}else{
alert(1)
}
}
export default createStore(reducer,newJson(localStorage.getItem('zylRoot')),applyMiddleware(thunk));
Router:
import React from 'react';
import { BrowserRouter, HashRouter } from 'react-router-dom';
import App from './App.js';
import { Provider } from 'react-redux';
import Store from './store/store.js';
const unsubscribe = Store.subscribe(() => {
localStorage.setItem("zylRoot", JSON.stringify(Store.getState()))
})
const Router = () => (
<BrowserRouter>
<Provider store={Store}>
<App />
</Provider>
</BrowserRouter>
)
export default Router;