Getting Started / Quickstart

Quickstart

Add intent-aware actions to a Next.js app in three steps.

1 · Install

$ npm install intent-link

2 · Wrap your app once

Mount IntentProvider once in your root layout. It runs the shared intent engine for everything inside it.

// app/layout.tsx
import { IntentProvider } from "intent-link"

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <IntentProvider>{children}</IntentProvider>
      </body>
    </html>
  )
}

Use IntentLink like a normal Next.js link and put the work you want to start early inside onIntent.

"use client"

import { IntentLink } from "intent-link"
import { useRouter } from "next/navigation"

function ProductCard({ href }: { href: string }) {
  const router = useRouter()
  return (
    <IntentLink href={href} onIntent={() => router.prefetch(href)}>
      View product
    </IntentLink>
  )
}
That is all most applications need. The library does not prefetch automatically—you choose what onIntent does.