In app router, server component, how can I get the current url (similar of window.location) #63587
-
Im using App router. GPT offered me to try |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
For more, here |
Beta Was this translation helpful? Give feedback.
-
It is not a rest api handler, so I don't have a request. |
Beta Was this translation helpful? Give feedback.
-
You can get it from headers |
Beta Was this translation helpful? Give feedback.
-
useServerRequest doesn’t exist in Next.js. Example:
✅ Works in Server Components If you also need the full path (not just origin), you can read: const path = h.get('x-invoke-path') || ''; |
Beta Was this translation helpful? Give feedback.
request.nextUrl.pathname;
For more, here