UNPKG

easy-page-router

Version:

easy-page-router is a lightweight and easy-to-use JavaScript routing package that simplifies navigation in vanilla JavaScript, React, and React Native applications.

36 lines (35 loc) 1.33 kB
import React, { ReactNode } from "react"; export type Actions = { push: (to: string) => void; back: () => void; forward: () => void; }; export type RouterProviderProps = { scrollSpeed?: number; scrollAlways?: boolean; noScroll?: boolean; onPageChange?: (href: string) => void; children: ReactNode; }; export declare function RouterProvider({ children, onPageChange, scrollSpeed, scrollAlways, noScroll, }: RouterProviderProps): React.JSX.Element; export type RenderAnimationProps = PageProps & { page: ReactNode; }; export type RouterProps = { renderPage: (props: PageProps) => ReactNode; renderAnimation?: (props: RenderAnimationProps) => ReactNode; }; export declare function Router({ renderPage, renderAnimation }: RouterProps): React.JSX.Element; export type PageState = "active" | "back" | "forward"; export type PageProps = { pageKey: string; href: string; to: string; path: string[]; searchParams: Record<string, string>; state: PageState; }; export declare function getPageProps(pageKey: string, href: string, index: number, actualIndex: number): PageProps; export type RouterHook = PageProps & Actions; export declare function useRouter(): RouterHook; export declare function scrollToTop(time: number, startScroll?: number, startTime?: number): void;