-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (41 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react';
import ReactDOM from 'react-dom';
//rudex
import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga'
import { Provider, connect } from 'react-redux';
import registerServiceWorker from './registerServiceWorker';
//路由
import { HashRouter, BrowserRouter, Route, Switch, Redirect } from 'react-router-dom';
//组件
import './index.css';
import App from './App';
import Home from './components/home'
import inD from './components/index'
import Login from './components/login'
//redux
import reducer from './reducers/index'
//sage
import fetchUser from './sage/index'
const sagaMiddleware = createSagaMiddleware()
//store
let store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(fetchUser)
store.subscribe(() => {
console.log(store.getState()) // 获取更新后最新的state树
})
ReactDOM.render(
<Provider store={store}>
<HashRouter>
<Switch>{/*如果一个组件下有多个child,必须使用Switch*/}
<Route exact path="/" component={App} />
<Route path="/home" component={Home} />
<Route path="/login" component={Login} />
<Route path="/in" component={inD} />
</Switch>
</HashRouter>
</Provider>, document.getElementById('root'));
registerServiceWorker();