Replies: 1 comment
|
the pathname is not available in server components by design. app router is designed to be able to re-use shared layouts across navigations, but that means they can't access the pathname -- otherwise, we'd risk displaying a stale pathname in a shared layout. also note that middleware also makes this difficult. if i rewrite |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Goals
In Client Components, we have access to usePathname() from next/navigation, which makes accessing the current pathname straightforward and synchronous.
Provide a built-in API for Server Components to access the current pathname without requiring:
Background
Currently, Server Components do not have direct access to the current pathname.
What we do now:
Example of the current workaround:
Problems with this approach:
Accessing the current pathname is a very common requirement (e.g., active nav links), and the current solution feels over-engineered.
Proposal
Introduce a built-in synchronous API for Server Components, such as:
Requirements:
Why This Matters:
All reactions