Capítulo 183 de 456
Track the pending state of a <Link> navigation to show subtle inline feedback (e.g. a shimmer) while navigation completes. Prefer route-level loading.js fallbacks and prefetching first; use this only as a targeted patch for a slow transition.
{ pending: boolean }; must be used within a descendant component of <Link>.true before history updates, false after.'use client'
import Link from 'next/link'
import { useLinkStatus } from 'next/link'
function Hint() {
const { pending } = useLinkStatus()
return <span aria-hidden className={`link-hint ${pending ? 'is-pending' : ''}`} />
}
export default function Header() {
return (
<header>
<Link href="/dashboard" prefetch={false}>
<span className="label">Dashboard</span> <Hint />
</Link>
</header>
)
}
Hint fica dentro do <Link> e reage ao estado pendente sem alterar o layout do link em si.| Property | Type | Description |
|---|---|---|
| pending | boolean | true before history updates, false after |
useLinkStatus só depois de identificar uma transição lenta específica, e prefira corrigir a causa raiz com prefetch ou loading.js.<Link> descendente; fora do Pages Router (que sempre retorna { pending: false }).animation-delay (~100ms) para evitar flash em navegações rápidas.