How to get params and searchParams in server component
Unanswered
Istrian Coarse-haired Hound posted this in #help-forum
Istrian Coarse-haired HoundOP
below is my next js structure
app folder
app/layout.js
app/page.js
components folder
components/layout
components/layout/layout.js
components/layout/menu.js
is there any way i can get params and searchParams in menu.js file?
I want to use server component to create menu, i know i can get using usePathname and useSearchParams but to do that i have create it client component
actually i need path name and search params to add active class in menu. i have many pages in my website and not using [slug] structure so its not possible for me to add Menu in each page
app folder
app/layout.js
app/page.js
components folder
components/layout
components/layout/layout.js
components/layout/menu.js
is there any way i can get params and searchParams in menu.js file?
I want to use server component to create menu, i know i can get using usePathname and useSearchParams but to do that i have create it client component
actually i need path name and search params to add active class in menu. i have many pages in my website and not using [slug] structure so its not possible for me to add Menu in each page
6 Replies
Asian black bear
There is nothing wrong about making it a client component. It's one of the most common cases of client components to highlight active menu items.
Istrian Coarse-haired HoundOP
Its affecting on google page speed, otherwise i don't have any issue, my SEO manager told me you must have to improve site performance and i did almost everything for SEO now only menu is pending 

Asian black bear
A single addition to have menu items be part of the client-side bundle should not significantly affect the bundle size (and presumably the measured page speed).
You might want to investigate what's going on if there is a huge discrepancy.
But in general doing it client-side is completely fine, even more so considering that it's irrelevant what menu item is active for SEO anyways.
To answer your original question, it's not reliably possible to obtain the current path on the server and this is by design.