Is it possible to access the pathname in a Next.js server component? #71720
Answered
by
himanshu634
Sathyaraj-dev
asked this question in
App Router
-
|
I'm working with server components in Next.js and would like to know if there's a way to access the pathname directly within these components. In client components, I can use the useRouter hook to get the pathname, but I'm unsure how to achieve this in server components. Are there any built-in methods or approaches for accessing the current pathname in server components, particularly in the context of dynamic routes? Any guidance or examples would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Answered by
himanshu634
Oct 23, 2024
Replies: 1 comment 3 replies
-
|
You can do it by setting cookies from middleware, that is one option. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Sathyaraj-dev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do it by setting cookies from middleware, that is one option.