Search code examples
next.jsapp-routerreact-server-components

How to change part of layout based on current path in nextjs app router server component?


Like if the layout includes a nav, and I want to highlight the nav item on the current page. Is that possible, or do I need to make the nav item a client component, so I can use import { usePathname } from 'next/navigation';?


Solution

  • You need a client component. Server components can't change based on route changes, since they aren't interactive / don't have JS.