Why this matters
Integrates with the router and simplifies control flow.
Prefer redirect() and notFound() over manual 302/404 handling and custom components in App Router.
Integrates with the router and simplifies control flow.
Side-by-side examples engineers can pattern-match during review.
return NextResponse.redirect('/login', 302) inside page.tsximport { redirect, notFound } from 'next/navigation'
export default async function Page(){ const session = await getSession(); if(!session) redirect('/login'); const post = await getPost(); if(!post) notFound(); return <div>{post.title}</div> }Rendering a custom <NotFound /> componentnotFound() for a true 404From the same buckets as this rule.