|
1 | 1 | import React, { useEffect } from 'react' |
2 | 2 | import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom' |
3 | | -import { connect, useSelector, useDispatch } from 'react-redux' |
| 3 | +import { useSelector } from 'react-redux' |
4 | 4 |
|
| 5 | +// config |
5 | 6 | import routes from '@/routes' |
6 | | -// import { getWindowWidth } from '@/redux/app/actions' |
7 | | -import { getTagList, getCategoryList } from '@/redux/article/actions' |
| 7 | + |
| 8 | +// components |
| 9 | +import PublicComponent from '@/components/Public' |
8 | 10 |
|
9 | 11 | const App = props => { |
10 | | - const dispatch = useDispatch() // dispatch hooks |
11 | 12 | const role = useSelector(state => state.user.role) // 相当于 connect(state => state.user.role)(App) |
12 | 13 |
|
13 | | - // 初始化数据 类似 componentDidMount |
14 | | - useEffect(() => { |
15 | | - // dispatch(getWindowWidth()) |
16 | | - dispatch(getTagList()) |
17 | | - dispatch(getCategoryList()) |
18 | | - // props.getWindowWidth() |
19 | | - // props.getTagList() |
20 | | - // props.getCategoryList() |
21 | | - // |
22 | | - console.log('app did mount') |
23 | | - /*eslint react-hooks/exhaustive-deps: "off"*/ |
24 | | - }, []) |
25 | | - |
26 | 14 | // 解构 route |
27 | 15 | function renderRoutes(routes, contextPath) { |
28 | 16 | const children = [] |
@@ -61,45 +49,11 @@ const App = props => { |
61 | 49 | } |
62 | 50 |
|
63 | 51 | const children = renderRoutes(routes, '/') |
64 | | - return <BrowserRouter>{children}</BrowserRouter> |
| 52 | + return ( |
| 53 | + <BrowserRouter> |
| 54 | + {children} |
| 55 | + <PublicComponent /> |
| 56 | + </BrowserRouter>) |
65 | 57 | } |
66 | 58 |
|
67 | 59 | export default App |
68 | | - |
69 | | -// export default connect( |
70 | | -// state => ({ |
71 | | -// role: state.user.role |
72 | | -// }), |
73 | | -// { getWindowWidth, getTagList, getCategoryList } |
74 | | -// )(App) |
75 | | - |
76 | | -// example test |
77 | | -// import WebLayout from '@/layout/web' |
78 | | -// import AdminLayout from '@/layout/admin' |
79 | | -// import Example from '@/views/examples' |
80 | | - |
81 | | -// const App = () => { |
82 | | -// return ( |
83 | | -// <BrowserRouter> |
84 | | -// <Switch> |
85 | | -// <Route path='/test' component={Example} /> |
86 | | -// <Route |
87 | | -// path='/admin' |
88 | | -// render={props => ( |
89 | | -// <AdminLayout> |
90 | | -// <Route path='/admin/e' component={Example} exact /> |
91 | | -// </AdminLayout> |
92 | | -// )} |
93 | | -// /> |
94 | | -// <Route |
95 | | -// path='/' |
96 | | -// render={props => ( |
97 | | -// <WebLayout> |
98 | | -// <Route path='/e' component={Example} /> |
99 | | -// </WebLayout> |
100 | | -// )} |
101 | | -// /> |
102 | | -// </Switch> |
103 | | -// </BrowserRouter> |
104 | | -// ) |
105 | | -// } |
0 commit comments