how do I extract `shrubs` from the url `http://localhost:3000/shrubs` ?
Answered
i_lost_to_loba_kreygasm posted this in #help-forum
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
@i_lost_to_loba_kreygasm Can anyone tell me which hook do I use ?
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 component@i_lost_to_loba_kreygasm can you give an example with `useParams`? i just have ssomething like this
it looks like you don't have a dynamic fragment. Why do you want to get the
shrubs
?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
@i_lost_to_loba_kreygasm 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 🤔yeah but the searchbar component doesnt belong to the shrubs component
its seperate
<SearchProvider>
<Provider>
<Navbar/>
{children}
</Provider>
</SearchProvider>
here is the markup
@i_lost_to_loba_kreygasm yeah but the searchbar component doesnt belong to the shrubs component
ah ok, then you can use the hook
usePathname()
to retrieve the full pathnameAnswer
thank you 🙂
it works
happy to help
Barbary Lion
how can I achieve this same thing on server side ?