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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
| import { markRaw } from 'vue';
| import { createRouter, createWebHistory } from 'vue-router'; // createWebHashHistory, createWebHistory
| import type { Router, RouteRecordRaw, RouteComponent } from 'vue-router';
| import { Help as IconHelp } from '@element-plus/icons-vue';
|
| /* Layout */
| const Layout = ():RouteComponent => import('@/layout/index.vue');
|
| /* Router Modules */
| import componentsRouter from './modules/components';
| import chartsRouter from './modules/charts';
| import nestedRouter from './modules/nested';
| import tableRouter from './modules/table';
|
| /**
| * constantRoutes
| * a base page that does not have permission requirements
| * all roles can be accessed
| *
| * 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
| */
| export const constantRoutes:RouteRecordRaw[] = [
| {
| path: '/redirect',
| component: Layout,
| meta: { hidden: true },
| children: [
| {
| path: '/redirect/:path(.*)',
| component: () => import('@/views/redirect/index.vue')
| }
| ]
| },
| {
| path: '/login',
| component: () => import('@/views/login/index.vue'),
| meta: { hidden: true }
| },
| {
| path: '/auth-redirect',
| component: () => import('@/views/login/auth-redirect.vue'),
| meta: { hidden: true }
| },
| {
| path: '/404',
| component: () => import('@/views/error-page/404.vue'),
| meta: { hidden: true }
| },
| {
| path: '/401',
| component: () => import('@/views/error-page/401.vue'),
| meta: { hidden: true }
| },
| {
| path: '/',
| component: Layout,
| redirect: '/dashboard',
| children: [
| {
| path: 'dashboard',
| component: () => import('@/views/dashboard/index.vue'),
| name: 'Dashboard',
| meta: { title: '首页', icon: 'dashboard', affix: true }
| }
| ]
| },
| {
| path: '/documentation',
| component: Layout,
| children: [
| {
| path: 'index',
| component: () => import('@/views/documentation/index.vue'),
| name: 'Documentation',
| meta: { title: '文档', icon: 'documentation', affix: true }
| }
| ]
| },
| {
| path: '/guide',
| component: Layout,
| redirect: '/guide/index',
| children: [
| {
| path: 'index',
| component: () => import('@/views/guide/index.vue'),
| name: 'Guide',
| meta: { title: '引导页', icon: 'guide', noCache: true }
| }
| ]
| },
| {
| path: '/profile',
| component: Layout,
| redirect: '/profile/index',
| meta: { hidden: true },
| children: [
| {
| path: 'index',
| component: () => import('@/views/profile/index.vue'),
| name: 'Profile',
| meta: { title: '个人中心', icon: 'user', noCache: true }
| }
| ]
| }
| ];
|
| /**
| * asyncRoutes
| * the routes that need to be dynamically loaded based on user roles
| *
| * 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
| */
| export const asyncRoutes:RouteRecordRaw[] = [
| {
| path: '/permission',
| component: Layout,
| redirect: '/permission/page',
| name: 'Permission',
| meta: {
| alwaysShow: true, // will always show the root menu
| title: '权限测试页',
| icon: 'lock',
| roles: ['admin', 'editor'] // you can set roles in root nav
| },
| children: [
| {
| path: 'page',
| component: () => import('@/views/permission/page.vue'),
| name: 'PagePermission',
| meta: {
| title: '页面权限',
| roles: ['admin'] // or you can only set roles in sub nav
| }
| },
| {
| path: 'directive',
| component: () => import('@/views/permission/directive.vue'),
| name: 'DirectivePermission',
| meta: {
| title: '指令权限'
| // if do not set roles, means: this page does not require permission
| }
| },
| {
| path: 'role',
| component: () => import('@/views/permission/role.vue'),
| name: 'RolePermission',
| meta: {
| title: '角色权限',
| roles: ['admin']
| }
| }
| ]
| },
|
| {
| path: '/icon',
| component: Layout,
| children: [
| {
| path: 'index',
| component: () => import('@/views/icons/index.vue'),
| name: 'Icons',
| meta: { title: '图标', icon: 'icon', noCache: true }
| }
| ]
| },
|
| // /** when your routing map is too long, you can split it into small modules **/
| componentsRouter,
| chartsRouter,
| nestedRouter,
| tableRouter,
|
| {
| path: '/example',
| component: Layout,
| redirect: '/example/list',
| name: 'Example',
| meta: {
| title: '综合示例',
| icon: markRaw(IconHelp)
| },
| children: [
| {
| path: 'create',
| component: () => import('@/views/example/create.vue'),
| name: 'CreateArticle',
| meta: { title: '创建文章', icon: 'edit' }
| },
| {
| path: 'edit/:id(\\d+)',
| component: () => import('@/views/example/edit.vue'),
| name: 'EditArticle',
| meta: { hidden: true, title: '编辑文章', noCache: true, activeMenu: '/example/list' }
| },
| {
| path: 'list',
| component: () => import('@/views/example/list.vue'),
| name: 'ArticleList',
| meta: { title: '文章列表', icon: 'list' }
| }
| ]
| },
|
| {
| path: '/tab',
| component: Layout,
| children: [
| {
| path: 'index',
| component: () => import('@/views/tab/index.vue'),
| name: 'Tab',
| meta: { title: 'Tabs标签页', icon: 'tab' }
| }
| ]
| },
|
| {
| path: '/error',
| component: Layout,
| redirect: 'noRedirect',
| name: 'ErrorPages',
| meta: {
| title: '错误页面',
| icon: '404'
| },
| children: [
| {
| path: '401',
| component: () => import('@/views/error-page/401.vue'),
| name: 'Page401',
| meta: { title: '401', noCache: true }
| },
| {
| path: '404',
| component: () => import('@/views/error-page/404.vue'),
| name: 'Page404',
| meta: { title: '404', noCache: true }
| }
| ]
| },
|
| {
| path: '/error-log',
| component: Layout,
| children: [
| {
| path: 'log',
| component: () => import('@/views/error-log/index.vue'),
| name: 'ErrorLog',
| meta: { title: '错误日志', icon: 'bug' }
| }
| ]
| },
|
| {
| path: '/excel',
| component: Layout,
| redirect: '/excel/export-excel',
| name: 'Excel',
| meta: {
| title: 'Excel',
| icon: 'excel'
| },
| children: [
| {
| path: 'export-excel',
| component: () => import('@/views/excel/export-excel.vue'),
| name: 'ExportExcel',
| meta: { title: '导出 Excel' }
| },
| {
| path: 'export-selected-excel',
| component: () => import('@/views/excel/select-excel.vue'),
| name: 'SelectExcel',
| meta: { title: '导出 已选择项' }
| },
| {
| path: 'export-merge-header',
| component: () => import('@/views/excel/merge-header.vue'),
| name: 'MergeHeader',
| meta: { title: '导出 多级表头' }
| },
| {
| path: 'upload-excel',
| component: () => import('@/views/excel/upload-excel.vue'),
| name: 'UploadExcel',
| meta: { title: '上传 Excel' }
| }
| ]
| },
|
| {
| path: '/zip',
| component: Layout,
| redirect: '/zip/download',
| name: 'Zip',
| meta: { alwaysShow: true, title: 'Zip', icon: 'zip' },
| children: [
| {
| path: 'download',
| component: () => import('@/views/zip/index.vue'),
| name: 'ExportZip',
| meta: { title: '导出 Zip' }
| }
| ]
| },
|
| {
| path: '/pdf',
| component: Layout,
| redirect: '/pdf/index',
| children: [
| {
| path: 'index',
| component: () => import('@/views/pdf/index.vue'),
| name: 'PDF',
| meta: { title: 'PDF', icon: 'pdf' }
| }
| ]
| },
| {
| path: '/pdf/download',
| component: () => import('@/views/pdf/download.vue'),
| meta: { hidden: true }
| },
|
| {
| path: '/theme',
| component: Layout,
| children: [
| {
| path: 'index',
| component: () => import('@/views/theme/index.vue'),
| name: 'Theme',
| meta: { title: '主题', icon: 'theme' }
| }
| ]
| },
|
| {
| path: '/clipboard',
| component: Layout,
| children: [
| {
| path: 'index',
| component: () => import('@/views/clipboard/index.vue'),
| name: 'ClipboardDemo',
| meta: { title: '剪贴板', icon: 'clipboard' }
| }
| ]
| },
|
| {
| path: '/external-link',
| component: Layout,
| children: [
| {
| path: 'https://element-plus.midfar.com',
| meta: { title: '外链', icon: 'link' },
| redirect: ''
| }
| ]
| },
|
| {
| path: '/my-demo',
| component: Layout,
| name: 'MyDemo',
| meta: {
| title: '我的示例',
| icon: 'component'
| },
| children: [
| {
| path: 'element-demo',
| component: () => import('@/views/mydemo/ElementDemo.vue'),
| name: 'ElementDemo',
| meta: { title: 'Element 示例', icon: 'skill' }
| },
| {
| path: 'store-demo',
| component: () => import('@/views/mydemo/StoreDemo.vue'),
| name: 'StoreDemo',
| meta: { title: 'Store 示例', icon: 'lock' }
| }
| ]
| },
|
| // 404 page must be placed at the end !!!
| { path: '/:pathMatch(.*)*', redirect: '/404', meta: { hidden: true }}
| ];
|
| console.log('BASE_URL=', import.meta.env);
|
| const createTheRouter = ():Router => createRouter({
| // history: createWebHashHistory(import.meta.env.BASE_URL),
| // 注意,如果要配置 HTML5 模式,则需要修改nginx配置,参考资料:
| // https://router.vuejs.org/zh/guide/essentials/history-mode.html
| history: createWebHistory(import.meta.env.BASE_URL),
| scrollBehavior: () => ({ top: 0 }),
| routes: constantRoutes
| });
|
| interface RouterPro extends Router {
| matcher: unknown;
| }
|
| const router = createTheRouter() as RouterPro;
|
| // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
| export function resetRouter() {
| const newRouter = createTheRouter() as RouterPro;
| router.matcher = newRouter.matcher; // reset router
| }
|
| export default router;
|
|