Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get referrer value in NextJS?

I am using NextJS routing, but when I try to use document.referrer in my code, it does not return any value. How can I resolve this issue?

I am using the router.events.on method to listen for changes in navigation, but I haven't found a way to retrieve the referrer value.

like image 812
Vishal Avatar asked Oct 27 '25 03:10

Vishal


1 Answers

The headers() function from NextJS may be helpful. Here's an example from the docs:

import { headers } from 'next/headers'
 
export default function Page() {
  const headersList = headers()
  const referer = headersList.get('referer')
 
  return <div>Referer: {referer}</div>
}
like image 63
Hel Nershing Thapa Avatar answered Oct 30 '25 16:10

Hel Nershing Thapa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!