Skip to content

Commit b43c925

Browse files
committed
feat(projects): add custom route exception
1 parent 4955f1a commit b43c925

File tree

8 files changed

+86
-31
lines changed

8 files changed

+86
-31
lines changed

build/plugins/router.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export function setupElegantRouter() {
88
base: 'src/layouts/base-layout/index.vue',
99
blank: 'src/layouts/blank-layout/index.vue'
1010
},
11+
customRoutes: {
12+
names: ['exception_403', 'exception_404', 'exception_500']
13+
},
1114
routePathTransformer(routeName, routePath) {
1215
const key = routeName as RouteKey;
1316

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"vue-router": "4.2.5"
6161
},
6262
"devDependencies": {
63-
"@elegant-router/vue": "0.3.2",
63+
"@elegant-router/vue": "0.3.4",
6464
"@iconify/json": "2.2.170",
6565
"@sa/scripts": "workspace:*",
6666
"@sa/uno-preset": "workspace:*",

pnpm-lock.yaml

Lines changed: 12 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/langs/en-us.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ const local: App.I18n.Schema = {
121121
'multi-menu_first_child': 'Menu One Child',
122122
'multi-menu_second': 'Menu Two',
123123
'multi-menu_second_child': 'Menu Two Child',
124-
'multi-menu_second_child_home': 'Menu Two Child Home'
124+
'multi-menu_second_child_home': 'Menu Two Child Home',
125+
exception: 'Exception',
126+
exception_403: '403',
127+
exception_404: '404',
128+
exception_500: '500'
125129
},
126130
page: {
127131
login: {

src/locales/langs/zh-cn.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ const local: App.I18n.Schema = {
121121
'multi-menu_first_child': '菜单一子菜单',
122122
'multi-menu_second': '菜单二',
123123
'multi-menu_second_child': '菜单二子菜单',
124-
'multi-menu_second_child_home': '菜单二子菜单首页'
124+
'multi-menu_second_child_home': '菜单二子菜单首页',
125+
exception: '异常页',
126+
exception_403: '403',
127+
exception_404: '404',
128+
exception_500: '500'
125129
},
126130
page: {
127131
login: {

src/router/elegant/transform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ function transformElegantRouteToVueRoute(
143143
const routeMap: RouteMap = {
144144
"root": "/",
145145
"not-found": "/:pathMatch(.*)*",
146+
"exception": "/exception",
147+
"exception_403": "/exception/403",
148+
"exception_404": "/exception/404",
149+
"exception_500": "/exception/500",
146150
"403": "/403",
147151
"404": "/404",
148152
"500": "/500",

src/router/routes/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,49 @@ const customRoutes: CustomRoute[] = [
2323
title: 'not-found',
2424
constant: true
2525
}
26+
},
27+
{
28+
name: 'exception',
29+
path: '/exception',
30+
component: 'layout.base',
31+
meta: {
32+
title: 'exception',
33+
i18nKey: 'route.exception',
34+
icon: 'ant-design:exception-outlined',
35+
order: 7
36+
},
37+
children: [
38+
{
39+
name: 'exception_403',
40+
path: '/exception/403',
41+
component: 'view.403',
42+
meta: {
43+
title: 'exception_403',
44+
i18nKey: 'route.exception_403',
45+
icon: 'ic:baseline-block'
46+
}
47+
},
48+
{
49+
name: 'exception_404',
50+
path: '/exception/404',
51+
component: 'view.404',
52+
meta: {
53+
title: 'exception_404',
54+
i18nKey: 'route.exception_404',
55+
icon: 'ic:baseline-web-asset-off'
56+
}
57+
},
58+
{
59+
name: 'exception_500',
60+
path: '/exception/500',
61+
component: 'view.500',
62+
meta: {
63+
title: 'exception_500',
64+
i18nKey: 'route.exception_500',
65+
icon: 'ic:baseline-wifi-off'
66+
}
67+
}
68+
]
2669
}
2770
];
2871

src/typings/elegant-router.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ declare module "@elegant-router/types" {
1717
export type RouteMap = {
1818
"root": "/";
1919
"not-found": "/:pathMatch(.*)*";
20+
"exception": "/exception";
21+
"exception_403": "/exception/403";
22+
"exception_404": "/exception/404";
23+
"exception_500": "/exception/500";
2024
"403": "/403";
2125
"404": "/404";
2226
"500": "/500";
@@ -54,6 +58,10 @@ declare module "@elegant-router/types" {
5458
RouteKey,
5559
| "root"
5660
| "not-found"
61+
| "exception"
62+
| "exception_403"
63+
| "exception_404"
64+
| "exception_500"
5765
>;
5866

5967
/**
@@ -84,6 +92,7 @@ declare module "@elegant-router/types" {
8492
CustomRouteKey,
8593
| "root"
8694
| "not-found"
95+
| "exception"
8796
>;
8897

8998
/**
@@ -113,6 +122,9 @@ declare module "@elegant-router/types" {
113122
CustomRouteKey,
114123
| "root"
115124
| "not-found"
125+
| "exception_403"
126+
| "exception_404"
127+
| "exception_500"
116128
>;
117129

118130
/**
@@ -241,7 +253,7 @@ declare module "@elegant-router/types" {
241253
name: K;
242254
path: RouteMap[K];
243255
component: `layout.${RouteLayout}`;
244-
children: (CustomCenterLevelRoute<GetChildRouteKey<K>> | CustomLastLevelRoute<K>)[];
256+
children: (CustomCenterLevelRoute<GetChildRouteKey<K>> | CustomLastLevelRoute<GetChildRouteKey<K>>)[];
245257
}
246258
: never;
247259

0 commit comments

Comments
 (0)