@generouted/react-router
Version:
Generated file-based routes for React Router and Vite
74 lines (68 loc) • 3.08 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import { LinkProps as LinkProps$1, NavigateProps as NavigateProps$1, NavigateOptions as NavigateOptions$1 } from 'react-router-dom';
type To<Pathname = string> = {
pathname: Pathname;
search?: string;
hash?: string;
};
type ComponentProps<Path extends string | To, Params extends Record<string, any>> = Path extends keyof Params ? {
to: Path;
params: Params[Path];
} : Path extends {
pathname: infer Pathname;
} ? Pathname extends keyof Params ? {
to: To<Pathname>;
params: Params[Pathname];
} : {
to: To<Pathname>;
params?: never;
} : {
to: Path;
params?: never;
};
type LinkProps<Path extends string | To, Params extends Record<string, any>> = Omit<LinkProps$1, 'to'> & ComponentProps<Path, Params>;
type NavigateProps<Path extends string | To, Params extends Record<string, any>> = Omit<NavigateProps$1, 'to'> & ComponentProps<Path, Params>;
type NavigateOptions<Path extends string | To | number, Params extends Record<string, any>> = Path extends number ? [] : Path extends keyof Params ? [NavigateOptions$1 & {
params: Params[Path];
}] : Path extends {
pathname: infer Pathname;
} ? Pathname extends keyof Params ? [NavigateOptions$1 & {
params: Params[Pathname];
}] : [NavigateOptions$1 & {
params?: never;
}] | [] : [NavigateOptions$1 & {
params?: never;
}] | [];
declare const components: <Path extends string, Params extends Record<string, any>>() => {
Link: <P extends Path | To<Path>>({ to, params, ...props }: LinkProps<P, Params>) => react_jsx_runtime.JSX.Element;
Navigate: <P_1 extends Path | To<Path>>({ to, params, ...props }: LinkProps<P_1, Params>) => react_jsx_runtime.JSX.Element;
};
declare const hooks: <Path extends string, Params extends Record<string, any>, ModalPath extends string>() => {
useParams: <P extends keyof Params>(path: P) => Params[P];
useNavigate: () => <P_1 extends number | Path | To<Path>>(to: P_1, ...[options]: NavigateOptions<P_1, Params>) => void;
useModals: () => {
current: any;
open: <P_2 extends Path>(path: ModalPath, options?: (NavigateOptions$1 & (P_2 extends keyof Params ? {
at?: P_2 | undefined;
params: Params[P_2];
} : {
at?: P_2 | undefined;
params?: undefined;
})) | undefined) => void;
close: <P_3 extends Path>(options?: (NavigateOptions$1 & (P_3 extends keyof Params ? {
at?: P_3 | undefined;
params: Params[P_3];
} : {
at?: P_3 | undefined;
params?: undefined;
})) | undefined) => void;
};
};
declare const utils: <Path extends string, Params extends Record<string, any>>() => {
redirect: <P extends Path>(url: P, ...[options]: P extends keyof Params ? [(number | ResponseInit) & {
params: Params[P];
}] : [] | [(number | ResponseInit) & {
params?: undefined;
}]) => Response;
};
export { type LinkProps, type NavigateOptions, type NavigateProps, type To, components, hooks, utils };