Suppose you have a root layout with a header, footer, and main. The header includes the whole navigation logic and the footer secondary navigations and other sections. The page is rendered inside main, while the header and the footer are mostly static.
Now, what do I mean by mostly... A few parts are dependent on the current route or page data.
- The currently active navigation item should be marked as active.
- A language switcher component (potentially deeply nested in the header/footer) needs links for other versions of the same page (e.g. translated URL segments).
The first case should be trivial, because you can just use usePathname and match it with the navigation item's href.
However, the second case needs data from the backend (the translated URLs of the current page), which is not straightforward.
Can you somehow SSR and cache the language switcher? How would you do this without having to do a client side fetching? (Client side fetching is worse UX than if it's just a server component that is loaded based on the page data you already fetch for each page)