Use the Link component and useRouter for fast client-side navigation in Next.js.
import Link from "next/link";
export default function Navigation() {
return (
<nav>
<Link href="/">Home</Link>
<Link href="/about">About</Link>
<Link href="/blog">Blog</Link>
</nav>
);
}<Link href="/contact" className="nav-link">Contact</Link>import Link from "next/link";
export default function PostList({ posts }) {
return (
<ul>
{posts.map(post => (
<li key={post.id}>
<Link href={`/blog/${post.slug}`}>
{post.title}
</Link>
</li>
))}
</ul>
);
}<Link
href={{
pathname: "/blog/[slug]",
query: { slug: post.slug }
}}
>
{post.title}
</Link><Link href="/about" prefetch={true}>
About
</Link><Link href="/api/heavy-data" prefetch={false}>
Load Data
</Link>import { useRouter } from "next/navigation";
const router = useRouter();
function prefetchAbout() {
router.prefetch("/about");
}import { useRouter } from "next/navigation";
export default function LoginForm() {
const router = useRouter();
async function handleSubmit(e) {
e.preventDefault();
// authenticate...
router.push("/dashboard");
}
return <form onSubmit={handleSubmit}>...</form>;
}router.push("/new-page"); // Add to history
router.replace("/new-page"); // Replace history
router.back(); // Go back
router.forward(); // Go forward"use client";
import { usePathname } from "next/navigation";
import Link from "next/link";
export default function Navigation() {
const pathname = usePathname();
return (
<nav>
<Link
href="/"
className={pathname === "/" ? "active" : ""}
>
Home
</Link>
<Link
href="/about"
className={pathname === "/about" ? "active" : ""}
>
About
</Link>
</nav>
);
}Use the useRouter hook from next/navigation and call router.push('/destination') after your async logic completes. For replacing history instead of pushing, use router.replace('/destination') to prevent users from navigating back.
Pass the interpolated path directly to Link's href: <Link href={/products/${product.id}}>. For complex routes, you can also pass an object: href={{ pathname: '/products/[id]', query: { id: product.id } }}.
Use the usePathname hook from next/navigation to get the current path, then compare it to the link's href to conditionally apply an active CSS class or style.
In production, Next.js prefetches linked pages when the Link enters the viewport, which speeds up navigation. You can disable this per-link with the prefetch={false} prop if the destination is rarely visited or costly to prefetch.