/** * Represents a single breadcrumb segment generated from the URL path. */ export interface Breadcrumb { /** The capitalized name of the path segment (e.g., "Products") */ name: string; /** The absolute path leading up to this segment (e.g., "/products") */ path: string; } /** * The complete parsed representation of the current browser URL. */ export interface UseURLReturn { /** The full URL string (e.g., "https://example.com/path?q=1") */ href: string; /** The protocol, including the colon (e.g., "https:") */ protocol: string; /** The host, including port if present (e.g., "example.com:8080") */ host: string; /** The hostname, excluding port (e.g., "example.com") */ hostname: string; /** The port number as a string (e.g., "8080"), or empty string if default */ port: string; /** The path component of the URL (e.g., "/products/mobile") */ pathname: string; /** The hash fragment, including the hash symbol (e.g., "#preview") */ hash: string; /** The query string, including the question mark (e.g., "?page=2") */ search: string; /** The URL origin (e.g., "https://example.com") */ origin: string; /** An object containing parsed query parameters. Duplicate keys form arrays. */ query: Record; /** The path split into an array of segments (e.g., ["products", "mobile"]) */ segments: string[]; /** The detected filename without extension, if present (e.g., "image") */ filename: string | null; /** The detected file extension, if present (e.g., "png") */ extension: string | null; /** The parent directory path (e.g., "/products") */ parent: string; /** The depth level of the current path (number of segments) */ depth: number; /** The pathname of the previous URL before the last navigation, or null if initial */ previous: string | null; /** True if the user has navigated away from the previous path in this session */ changed: boolean; /** True if the current pathname is the root ("/") */ isHome: boolean; /** True if the protocol is "https:" */ isSecure: boolean; /** Reserved for future cross-domain navigation checks */ isExternal: boolean; /** An array of progressively built breadcrumbs up to the current path */ breadcrumbs: Breadcrumb[]; /** A timestamp (ms) of exactly when the URL last changed */ timestamp: number; } /** * A highly optimized hook that provides complete, deeply-parsed information about the current browser URL. * It automatically reacts to programmatic navigation (pushState/replaceState), * back/forward buttons (popstate), and hash changes without needing an external routing library. * It is fully SSR safe and highly optimized with `useMemo` to prevent unnecessary downstream re-renders. * * @returns {UseURLReturn} A stable object containing the parsed URL data and navigation metadata. * * @example * ```tsx * const { pathname, query, segments, changed, previous } = useURL(); * * console.log(pathname); // "/products/shoes" * console.log(query.page); // "2" * console.log(segments[0]); // "products" * ``` */ export declare function useURL(): UseURLReturn;