fluxel
Version:
An ultra-lightweight, high-performance library for efficient DOM building and dynamic web UIs
45 lines (44 loc) • 1.41 kB
TypeScript
import type { FluxelComponent, FluxelJSXElement, StateParam, TypedEventTarget } from "../type.js";
export type RouteConfig = {
[pattern: string]: (() => string | Node) | (() => Promise<() => string | Node>);
};
export type RouterMode = "history" | "hash";
export type RouterOptions = {
basePath?: string;
mode?: RouterMode;
fallback?: FluxelComponent<{}, string | Node> | FluxelComponent<{}, FluxelJSXElement>;
};
export type Router = {
mode: RouterMode;
basePath: string;
pathname: string;
route: string | null;
params: Readonly<Record<string, string>>;
query: Readonly<StateParam<Record<string, string>>>;
Provider: FluxelComponent<{
classList?: string[];
}, string | Node>;
navigate(path: string, options: {
replace?: boolean;
}): void;
deferUpdate(process: () => Promise<void>): void;
};
export declare const routerEventTarget: TypedEventTarget<{
"popstate": CustomEvent;
}>;
export declare function createRouter(config: RouteConfig, options?: RouterOptions): Router;
export interface UseRouter<R = Router> {
(option?: {
optional?: false;
}): R;
(option?: {
optional: true;
}): R | null;
(option?: {
optional?: boolean;
}): R | null;
}
export declare const useRouter: UseRouter;
export declare function globalNavigate(path: string, options?: {
replace?: boolean;
}): void;