Next.js (App Router): How to get the Request headers in Next.js app router

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Here’s how to retrieve request headers in Next.js (app router).

To access request headers, use the ‘headers’ function from the ‘next/headers’ package:

import { headers } from 'next/headers'

export default function MyComponent() {
  const headersList = headers()
  const referer = headersList.get('referer')
  
  return <div>Referer: {referer}</div>
}

The ‘headers’ function is read-only (to set headers, use middleware or the ‘next/server’ package).

Note that this function only works in Server Components.

For client components, you need to pass the headers from a server component, for example via props:

import { headers } from 'next/headers'
import ClientComponent from './ClientComponent'

export default function ServerComponent() {
  const headersList = headers()
  const userAgent = headersList.get('user-agent')

  return <ClientComponent userAgent={userAgent} />
}
'use client'

export default function ClientComponent({ userAgent }) {
  return <div>User Agent: {userAgent}</div>
}

Remember that you should only pass the specific header information needed by the client component, rather than the entire headers object, to maintain security and minimize data transfer.

Lessons in this unit:

0: Introduction
1: Server Actions
2: Next.js, passing an id to a server action
3: The use hook
4: use() and data fetching
5: The useFormStatus Hook
6: The useOptimistic hook
7: The useActionState hook
8: ▶︎ How to get the Request headers in Next.js app router
9: How to install shadcn-ui on latest Next.js beta-RC