Traditionally, navigating to a server-rendered page triggers a full page reload, clearing state, resetting scroll position, and blocking interactivity. Next.js avoids this with client-side transitions using the <Link> component.
Without a loading.tsx file, users must wait for the server response. Adding this file enables partial prefetching and shows a fallback UI:
// app/blog/[slug]/loading.tsx
export default function Loading() {
return <LoadingSkeleton />;
}If a dynamic route could be statically generated but lacks generateStaticParams, it falls back to dynamic rendering:
export async function generateStaticParams() {
const posts = await fetch('https://.../posts').then(res => res.json())
return posts.map(post => ({ slug: post.slug }))
}On slow networks, prefetching may not complete before a user clicks. Use useLinkStatus to show immediate feedback:
// app/ui/loading-indicator.tsx
'use client'
import { useLinkStatus } from 'next/link'
export default function LoadingIndicator() {
const { pending } = useLinkStatus()
return (
<span aria-hidden className={`link-hint ${pending ? 'is-pending' : ''}`} />
)
}To reduce resource usage, you can disable prefetching or enable it only on hover:
// app/ui/hover-prefetch-link.tsx
'use client'
import Link from 'next/link'
import { useState } from 'react'
function HoverPrefetchLink({ href, children }) {
const [active, setActive] = useState(false)
return (
<Link
href={href}
prefetch={active ? null : false}
onMouseEnter={() => setActive(true)}
>
{children}
</Link>
)
}The <Link> component must be hydrated before it can prefetch. To improve hydration:
@next/bundle-analyzer to reduce bundle sizeNext.js supports window.history.pushState and replaceState to update the URL without reloading the page.
'use client'
import { useSearchParams } from 'next/navigation'
export default function SortProducts() {
const searchParams = useSearchParams()
function updateSorting(sortOrder) {
const params = new URLSearchParams(searchParams.toString())
params.set('sort', sortOrder)
window.history.pushState(null, '', `?${params.toString()}`)
}
}'use client'
import { usePathname } from 'next/navigation'
export function LocaleSwitcher() {
const pathname = usePathname()
function switchLocale(locale) {
const newPath = `/${locale}${pathname}`
window.history.replaceState(null, '', newPath)
}
}Client-side transitions in Next.js enable fast, responsive navigation while preserving state and layout. By using loading.tsx, useLinkStatus, and the History API, you can optimize dynamic routes and deliver instant feedback to users.