Next.js Discord

Discord Forum

getting url value server side

Unanswered
Tonkinese posted this in #help-forum
Open in Discord
TonkineseOP
Hey

I need to make use if of a url param (siteSlug) in a server component. How can I get access to this without passing the value from page.tsx/client component as a prop?

9 Replies

There are many ways you can do this.
- In a middleware.ts you can set a header containing the value of the slug and then access it via a headers instance (more complex)
- Create a headers instance and then get the pathname by running headers().get("host") and then filter out the origin and get your slug
- Also headers().get("referer") or headers().get("referrer")
@Tonkinese
TonkineseOP
Thanks!
No worries, hope this solves your problem.
Original message was deleted
If it does, don't forget this.