UNPKG

react-router-decorator

Version:

基于 react-router-dom 封装的路由工具,提供装饰器/函数模式设置路由,自动排序,支持嵌套路由

74 lines (73 loc) 2.47 kB
import { IParseOptions } from 'qs'; import * as React from 'react'; import { RouteObject } from 'react-router-dom'; import type { PageComponent, PageOptions, PageWrapperProps, PageWrapperType, Query, RenderOptions, RouteOption, WithWrappedProps } from './type'; export * from 'react-router-dom'; export type { PageWrapperProps, PageWrapperType, WithWrappedProps }; /** * 将地址栏 search 转换为 query 对象 */ export declare const transSearch2Query: (search?: string, options?: IParseOptions) => Query; /** * hook 获取地址栏中的 query 对象 */ export declare const useSearchQuery: (options?: IParseOptions) => Query; /** * 获取所有的路由绝对路径及相关配置 */ export declare const getRouteConfig: () => Record<string, RouteOption>; /** * 路由辅助工具,可渲染关键路由,方便开发人员切换页面 */ export declare const DevRouterHelper: React.FC<{ label?: string; }>; /** * 默认页面 Wrapper 附加自动解析 params、query 追加 navigate * @param props * @constructor */ export declare const PageWrapper: PageWrapperType; /** * 类装饰器,用于注册类组件路由 * @param path 路由路径 * @param options 附加参数 */ export declare const page: (path: string | '/' | '*', options?: PageOptions) => (Component: PageComponent) => void; /** * 函数注册路由,类组件和函数组件均可使用 * @param Component * @param path * @param options */ export declare const $page: (Component: PageComponent, path: string | '/' | '*', options?: PageOptions) => void; /** * 路由路径排序算法 * @param a * @param b */ export declare const routeSorter: (a: string, b: string) => 1 | -1; /** * 获取路由配置 * @param options */ export declare const getRoutes: (options: Omit<RenderOptions, 'type' | 'Wrapper'>, dataRouter?: boolean) => Array<RouteObject>; /** * By use useRoutes([...]) */ export declare const AppRoutes: (props: Omit<RenderOptions, 'type' | 'Wrapper'>) => React.ReactElement | null; /** * Router with Routes do not support the data APIs. */ export declare const AppRouter: (props: RenderOptions) => React.JSX.Element; /** * Router with Routes and support the Data APIs. */ export declare const DataRouter: (props: RenderOptions) => React.JSX.Element; /** * By ReactDOM.render * @param element * @param options * @deprecated when use React 18. */ export declare const renderApp: (element: HTMLElement, options?: RenderOptions) => void;