"use client"; import { Suspense, useEffect, useState } from "react"; import { usePathname, useSearchParams } from "next/navigation"; function RouteProgressInner() { const pathname = usePathname(); const searchParams = useSearchParams(); const [active, setActive] = useState(false); useEffect(() => { const onClick = (e: MouseEvent) => { if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) { return; } const el = (e.target as HTMLElement | null)?.closest?.("a[href]"); if (!el) return; const href = el.getAttribute("href"); if (!href || href.startsWith("http") || href.startsWith("mailto:") || href.startsWith("#")) { return; } if (!href.startsWith("/")) return; const nextPath = href.split("?")[0]; if (nextPath === window.location.pathname && href === `${window.location.pathname}${window.location.search}`) { return; } setActive(true); }; document.addEventListener("click", onClick, true); return () => document.removeEventListener("click", onClick, true); }, []); useEffect(() => { if (!active) return; const t = window.setTimeout(() => setActive(false), 350); return () => window.clearTimeout(t); }, [pathname, searchParams, active]); if (!active) return null; return (
); } export function RouteProgress() { return ( ); }