-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.tsx
157 lines (148 loc) · 3.9 KB
/
app.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import {
Outlet,
Route,
Routes,
} from 'react-router-dom'
import { useNavigate } from 'react-router'
import { Router, history } from '~history'
const context = require.context('@/pages', true, /index\.page\./)
const routePaths = context.keys().map((path: string) => {
const Component = context<{ default: () => JSX.Element }>(path)
path = path.replace(/\.(.*?)\/index\.page\.tsx$/, '$1')
return {
path,
Component,
}
})
const commonLiStyle = { marginRight: 10, color: 'blue', cursor: 'pointer' }
function Layout() {
const navigate = useNavigate()
return (
<>
<button onClick={() => navigate('/')}>回到首页</button>
<ul>
<li
style={commonLiStyle}
onClick={() => {
history.OPEN_ORDER({
/** 这里因为order下面又index.params.ts定义了传参类型,所以有参数类型提示,点击对应参数会跳到对应文件 */
order_id: '123',
enter_order_type: 'OPEN',
customer_names: ['name1', 'name2'],
})
}}
>
OPEN_ORDER
</li>
<li
style={commonLiStyle}
onClick={() => {
history.TO_ORDER({
/** 这里因为order下面又index.params.ts定义了传参类型,所以有参数类型提示,点击对应参数会跳到对应文件 */
order_id: '123',
enter_order_type: 'OPEN',
customer_names: ['name1', 'name2'],
})
}}
>
TO_ORDER
</li>
<li
style={commonLiStyle}
onClick={() => history.REPLACE_ORDER({
order_id: '123',
enter_order_type: 'REPLACE',
customer_names: ['name1', 'name2'],
})}
>
REPLACE_ORDER
</li>
</ul>
<ul>
<li
style={commonLiStyle}
onClick={() => history.OPEN_ORDER_DETAIL()}
>
OPEN_ORDER_DETAIL
</li>
<li
style={commonLiStyle}
onClick={() => history.TO_ORDER_DETAIL()}
>
TO_ORDER_DETAIL
</li>
<li
style={commonLiStyle}
onClick={() => history.REPLACE_ORDER_DETAIL()}
>
REPLACE_ORDER_DETAIL
</li>
</ul>
<ul>
<li
style={commonLiStyle}
onClick={() => history.OPEN_MY()}
>
OPEN_MY
</li>
<li
style={commonLiStyle}
onClick={() => history.TO_MY()}
>
TO_MY
</li>
<li
style={commonLiStyle}
onClick={() => history.OPEN_MY()}
>
REPLACE_MY
</li>
</ul>
<hr />
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
routePaths.filter(({ path }) => !['/order', '/order/detail', '/my'].includes(path)).map(({ path }) => {
const name = path.slice(1).toUpperCase().replace(/\//g, '_') || '$INDEX'
return (
<ul key={name}>
<li
style={commonLiStyle}
onClick={() => { history[`OPEN_${name}`]() }}
>
OPEN_{name}
</li>
<li
style={{ marginRight: 10, color: 'blue', cursor: 'pointer' }}
onClick={() => { history[`TO_${name}`]() }}
>
TO_{name}
</li>
<li
style={{ marginRight: 10, color: 'blue', cursor: 'pointer' }}
onClick={() => { history[`OPEN_${name}`]() }}
>
REPLACE_{name}
</li>
</ul>
)
})
}
<hr />
<Outlet />
</>
)
}
function App() {
return (
<Router>
<Routes>
<Route element={<Layout/>}>
{routePaths.map(({ path, Component }) => {
return <Route path={path} element={<Component.default />} key={path} />
})}
</Route>
</Routes>
</Router>
)
}
export default App