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.
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>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With