@gulibs/react-autoroutes-client
Version:
Client-side utilities for React auto routes
42 lines • 1.65 kB
TypeScript
import React from 'react';
import type { AuthOptions, GuardOptions, MiddlewareOptions } from './types';
/**
* 路由保护包装器的属性接口
*/
export interface RouteProtectionWrapperProps {
/** 守卫数组 */
guards?: (AuthOptions | GuardOptions | (() => Promise<boolean> | boolean))[];
/** 中间件数组 */
middlewares?: (MiddlewareOptions | ((context: any, next: () => void) => Promise<void> | void))[];
/** 加载时显示的元素 */
loadingElement?: React.ReactNode;
/** 要保护的组件 */
component: React.ReactNode;
/** 子组件(用于函数式用法) */
children?: React.ReactNode;
}
/**
* 路由保护包装器组件
*
* 用于保护路由,执行守卫检查和中间件逻辑
* 兼容原始库的 RouteProtectionWrapper
*/
export declare function RouteProtectionWrapper({ guards, middlewares, loadingElement, component, children }: RouteProtectionWrapperProps): import("react/jsx-runtime").JSX.Element;
/**
* 高阶组件形式的路由保护
*/
export declare function withRouteProtection<P extends object>(WrappedComponent: React.ComponentType<P>, options?: Omit<RouteProtectionWrapperProps, 'component' | 'children'>): {
(props: P): import("react/jsx-runtime").JSX.Element;
displayName: string;
};
/**
* Hook 形式的路由保护
*/
export declare function useRouteProtection(guards?: RouteProtectionWrapperProps['guards'], middlewares?: RouteProtectionWrapperProps['middlewares']): {
isLoading: boolean;
error: string | null;
hasAccess: boolean;
user: any;
};
export default RouteProtectionWrapper;
//# sourceMappingURL=components.d.ts.map