Replies: 2 comments
-
The answer is that you can't get server components to rerender on route change because they aren't rehydrated / don't have JS! 😆 Whatever part of the layout you need to change has to be a client component, where you can use |
Beta Was this translation helpful? Give feedback.
-
Hi, Getting the pathname requires a bit of setup from your side, but not middleware at all. Here's a long winded explanation: #63298 (comment) Since, often you don't want the pathname, or other, necessarily, but some data derived from it, you can use that trick to make it available. Just remember, that layouts are a bit quirky, and render after a page, but are cached on the client. So the same reasons to not do authentication in layouts, apply to not relying too much in context. |
Beta Was this translation helpful? Give feedback.
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
Ability to render something in layout.ts differently based on which path it's on
Non-Goals
No response
Background
Similar discussion: #50189
Current semi-alternative:
middleware:
in component:
The issue with this is that the component doesn't get rerendered on route change, so
currentPath
isn't updated.Proposal
Perhaps
pathname()
, similar toheaders()
?Beta Was this translation helpful? Give feedback.
All reactions