UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

36 lines 1.28 kB
export declare function initRouter(options?: RouterOptions): STXRouter; export declare function getRouter(): STXRouter | null; /** * STX Client-Side Router * * Lightweight SPA router for STX applications. * Intercepts navigation, fetches pages via AJAX, and swaps content. */ export declare interface RouterOptions { container?: string linkSelector?: string loadingClass?: string viewTransitions?: boolean cache?: boolean scrollToTop?: boolean onBeforeNavigate?: (url: string) => boolean | void onAfterNavigate?: (url: string) => void onError?: (error: Error, url: string) => void } declare class STXRouter { private options: Required<RouterOptions>; private cache: Map<string, CacheEntry>; private isNavigating: any; private currentUrl: string; constructor(options?: RouterOptions); init(): void; navigate(url: string, pushState?: any): Promise<void>; prefetch(url: string): Promise<void>; clearCache(): void; private handleClick(event: MouseEvent): void; private handlePopState(event: PopStateEvent): void; private fetchPage(url: string): Promise<{ html: string; title: string } | null>; private swapContent(content: { html: string; title: string }): Promise<void>; private cacheCurrentPage(): void; } export { STXRouter };