how do I extract `shrubs` from the url `http://localhost:3000/shrubs` ?
Answered
Siberian posted this in #help-forum
SiberianOP
Can anyone tell me which hook do I use ?
Answered by B33fb0n3
ah ok, then you can use the hook
usePathname()
to retrieve the full pathname14 Replies
if you have a dynamic segment, then you can directly access it via the params inside a server component. Or with
useParams()
inside a client componentSiberianOP
can you give an example with
useParams
? i just have ssomething like thisit looks like you don't have a dynamic fragment. Why do you want to get the
shrubs
?SiberianOP
its abit complicated . well , I have a searchbar component to search queries, if the search results is empty , I wanna filter the queries based on the page and not the whole json
ok, but when you are on the page
shrubs
then you already know, that you are on the page 🤔SiberianOP
yeah but the searchbar component doesnt belong to the shrubs component
its seperate
<SearchProvider>
<Provider>
<Navbar/>
{children}
</Provider>
</SearchProvider>
here is the markup
ah ok, then you can use the hook
usePathname()
to retrieve the full pathnameAnswer
SiberianOP
thank you 🙂
it works
happy to help
Barbary Lion
how can I achieve this same thing on server side ?