Skip to content

Commit 39eecf2

Browse files
committed
refactor: 优化路由相关的类型
1 parent 24a1f6f commit 39eecf2

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

src/types/api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ declare namespace Api {
174174
type IconType = '1' | '2';
175175

176176
type MenuPropsOfRoute = Pick<
177-
import('@ohh-889/react-auto-route').RouteMeta,
177+
import('@soybean-react/vite-plugin-react-router').RouteMeta,
178178
| 'activeMenu'
179179
| 'constant'
180180
| 'fixedIndexInTab'

src/types/app.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ declare namespace App {
161161

162162
/** Global namespace */
163163
namespace Global {
164-
type RouteLocationNormalizedLoaded = import('@sa/simple-router').Route;
165164
type RouteKey = import('@elegant-router/types').RouteKey;
166165
type RouteMap = import('@elegant-router/types').RouteMap;
167166
type RoutePath = import('@elegant-router/types').RoutePath;
@@ -193,7 +192,7 @@ declare namespace App {
193192
/** The menu i18n key */
194193
i18nKey?: I18n.I18nKey | null;
195194
/** The menu icon */
196-
icon?: React.FunctionComponentElement<IconProps>;
195+
icon?: React.ReactElement;
197196
/**
198197
* The menu key
199198
*
@@ -211,8 +210,7 @@ declare namespace App {
211210
};
212211

213212
/** Tab route */
214-
type TabRoute = Pick<RouteLocationNormalizedLoaded, 'meta' | 'name' | 'path'> &
215-
Partial<Pick<RouteLocationNormalizedLoaded, 'fullPath' | 'matched' | 'query'>>;
213+
type TabRoute = Router.Route;
216214

217215
/** The global tab */
218216
type Tab = {

src/types/auto-imports.d.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,43 @@ export {}
88
declare global {
99
const AButton: typeof import('antd')['Button']
1010
const ACard: typeof import('antd')['Card']
11+
const ACheckbox: typeof import('antd')['Checkbox']
12+
const AColorPicker: typeof import('antd')['ColorPicker']
1113
const AConfigProvider: typeof import('antd')['ConfigProvider']
14+
const ADivider: typeof import('antd')['Divider']
15+
const ADrawer: typeof import('antd')['Drawer']
1216
const ADropdown: typeof import('antd')['Dropdown']
17+
const AEmpty: typeof import('antd')['Empty']
18+
const AFlex: typeof import('antd')['Flex']
1319
const AForm: typeof import('antd')['Form']
20+
const AInput: typeof import('antd')['Input']
21+
const AMenu: typeof import('antd')['Menu']
22+
const AModal: typeof import('antd')['Modal']
1423
const ASegmented: typeof import('antd')['Segmented']
24+
const ASpace: typeof import('antd')['Space']
25+
const ASwitch: typeof import('antd')['Switch']
1526
const ATooltip: typeof import('antd')['Tooltip']
1627
const AWatermark: typeof import('antd')['Watermark']
28+
const BeyondHiding: typeof import('../components/BeyondHiding')['default']
1729
const ButtonIcon: typeof import('../components/ButtonIcon')['default']
30+
const DarkModeContainer: typeof import('../components/DarkModeContainer')['default']
31+
const FilpText: typeof import('../components/FilpText')['default']
32+
const FullScreen: typeof import('../components/FullScreen')['default']
33+
const IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined.tsx')['default']
34+
const IconGridiconsFullscreen: typeof import('~icons/gridicons/fullscreen.tsx')['default']
35+
const IconGridiconsFullscreenExit: typeof import('~icons/gridicons/fullscreen-exit.tsx')['default']
36+
const IconLocalLogo: typeof import('~icons/local/logo.tsx')['default']
37+
const IconMdiArrowDownThin: typeof import('~icons/mdi/arrow-down-thin.tsx')['default']
38+
const IconMdiArrowUpThin: typeof import('~icons/mdi/arrow-up-thin.tsx')['default']
39+
const IconMdiKeyboardEsc: typeof import('~icons/mdi/keyboard-esc.tsx')['default']
40+
const IconMdiKeyboardReturn: typeof import('~icons/mdi/keyboard-return.tsx')['default']
41+
const IconUilSearch: typeof import('~icons/uil/search.tsx')['default']
1842
const Link: typeof import('react-router-dom')['Link']
43+
const LookForward: typeof import('../components/LookForward')['default']
1944
const NavLink: typeof import('react-router-dom')['NavLink']
2045
const Navigate: typeof import('react-router-dom')['Navigate']
2146
const Outlet: typeof import('react-router-dom')['Outlet']
47+
const PinToggler: typeof import('../components/PinToggler')['default']
2248
const Route: typeof import('react-router-dom')['Route']
2349
const Routes: typeof import('react-router-dom')['Routes']
2450
const SvgIcon: typeof import('../components/SvgIcon')['default']
@@ -89,7 +115,6 @@ declare global {
89115
const useMap: typeof import('ahooks')['useMap']
90116
const useMemo: typeof import('react')['useMemo']
91117
const useMemoizedFn: typeof import('ahooks')['useMemoizedFn']
92-
const useMixMenuContext: typeof import('../hooks/common/menu')['useMixMenuContext']
93118
const useMobile: typeof import('../hooks/common/mobile')['useMobile']
94119
const useMount: typeof import('ahooks')['useMount']
95120
const useMouse: typeof import('ahooks')['useMouse']

src/types/elegant-router.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ declare module "@elegant-router/types" {
3131
"document_antd": "/document/antd";
3232
"logout": "/logout";
3333
"(base)_home": "/home";
34+
"(base)_manage": "/manage";
35+
"(base)_manage_menu": "/manage/menu";
36+
"(base)_user-center": "/user-center";
3437
"(blank)_login": "/login";
3538
"(blank)_login_code-login": "/login/code-login";
3639
"(blank)_login_register": "/login/register";
@@ -109,6 +112,11 @@ declare module "@elegant-router/types" {
109112
| "(base)_home"
110113
| "(base)_home"
111114
| "(base)"
115+
| "(base)_manage"
116+
| "(base)_manage_menu"
117+
| "(base)_manage_menu"
118+
| "(base)_user-center"
119+
| "(base)_user-center"
112120
| "(blank)"
113121
| "(blank)_login_code-login"
114122
| "(blank)_login_code-login"
@@ -126,7 +134,6 @@ declare module "@elegant-router/types" {
126134
| "root"
127135
| "root"
128136
| "root"
129-
| "root"
130137
>;
131138

132139
/**

src/types/router.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import '@ohh-889/react-auto-route';
1+
declare namespace Router {
2+
type UIMatch<Data = unknown, Handle = unknown> = import('react-router-dom').UIMatch<Data, Handle>;
23

3-
declare module '@ohh-889/react-auto-route' {
4-
interface RouteMeta {
4+
type RouteHandle = {
55
/**
66
* The menu key will be activated when entering the route
77
*
@@ -68,5 +68,9 @@ declare module '@ohh-889/react-auto-route' {
6868
* It can be used in document title
6969
*/
7070
title: string;
71-
}
71+
};
72+
73+
type Route<T = unknown> = UIMatch<T, RouteHandle> & {
74+
matched: UIMatch<T, RouteHandle>[];
75+
};
7276
}

0 commit comments

Comments
 (0)