-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.tsx
92 lines (84 loc) · 1.59 KB
/
base.tsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react';
import { BrowserRouter as Router, NavLink } from 'react-router-dom';
import { RouteConfig, AWRouter, RouteConfigComponentProps } from 'aw-react-router-helper';
interface RouteMeta {
name: string;
}
const Layout: React.FC<RouteConfigComponentProps<any, RouteMeta>> = ({
renderRoutes,
}) => {
return (
<>
<h1>A</h1>
<div>
<NavLink style={{ marginRight: '20px' }} to="/a/a1">a1</NavLink>
<NavLink style={{ marginRight: '20px' }} to="/a/a2">a2</NavLink>
<NavLink style={{ marginRight: '20px' }} to="/b">b</NavLink>
</div>
<div>
{renderRoutes()}
</div>
</>
);
}
const configs: RouteConfig<RouteMeta>[] = [
{
path: '/',
redirect: '/a',
},
{
path: '/a',
meta: {
name: 'a'
},
component: Layout,
routes: [
{
path: '/a',
redirect: '/a/a1',
},
{
path: '/a/a1',
component: () => {
return <p>a1</p>
},
},
{
path: '/a/a2',
component: () => {
return <p>a2</p>
},
}
],
},
{
path: '/b',
meta: {
name: 'b'
},
component: () => {
return (
<h1>B</h1>
);
},
}
];
export const routerManager = AWRouter.instance<AWRouter<RouteMeta>>().load({
configs,
middlewares: [
state => {
if (state.meta && state.meta.name) {
document.title = state.meta.name;
}
return '';
},
],
});
function App() {
return (
<Router>
{routerManager.render()}
</Router>
);
}
export default App;