-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter.jsx
62 lines (60 loc) · 2.18 KB
/
router.jsx
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
59
60
61
62
import { BrowserRouter as Router, Switch, Route, Redirect } from 'react-router-dom';
import React from 'react';
import path from 'path';
import { getBasename } from '@ice/stark-app';
import routes from '@/config/routes';
import { Provider } from 'react-redux';
import { LocaleProvider } from 'antd';
import StarkInjectionToStore from './stark';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import store from './store'
const RouteItem = props => {
const { redirect, path: routePath, component, key } = props;
if (redirect) {
return <Redirect exact key={key} from={routePath} to={redirect} />;
}
return <Route key={key} component={component} path={routePath} />;
};
export default () => {
return (
<Provider store={store} cuishijie="cuishijie">
<LocaleProvider locale={zhCN}>
<StarkInjectionToStore>
<Router basename={getBasename()}>
<Switch>
{routes.map((route, id) => {
const { component: RouteComponent, children, ...others } = route;
return (
<Route
key={id}
{...others}
component={props => {
return children ? (
<RouteComponent key={id} {...props}>
<Switch>
{children.map((child, idx) => {
const { path: childPath, ...childOthers } = child;
return (
<RouteItem
{...childOthers}
key={`${id}-${idx}`}
path={childPath && path.join(route.path, childPath)}
/>
);
})}
</Switch>
</RouteComponent>
) : (
<RouteItem key={id} {...props} />
);
}}
/>
);
})}
</Switch>
</Router>
</StarkInjectionToStore>
</LocaleProvider>
</Provider>
);
};