Next.js Discord

Discord Forum

get url in server side component, please help

Unanswered
Waterman posted this in #help-forum
Open in Discord
Avatar
WatermanOP
I have been struggling with this issue for so long and I don't think theres any idea I link my code, but I have been using next/headers but it only works in dev for me and not i production because everything is different there,

Please help with this issue, all I want is to get the current url on the page I am on, then being able to use it as a variable,

thanks

2 Replies

Avatar
Spectacled bear
Bump
Avatar
Alfonsus Ardani
You can retrieve the URL in middleware.ts from request object, set it into the header, then you can access the header with the added URL from middleware in the Server Components