Next.js Discord

Discord Forum

how do I extract `shrubs` from the url `http://localhost:3000/shrubs` ?

Answered
i_lost_to_loba_kreygasm posted this in #help-forum
Open in Discord
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 pathname
View full answer

14 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
@B33fb0n3 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
can you give an example with useParams? i just have ssomething like this
@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
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 pathname
Answer
thank you 🙂
it works
happy to help
Barbary Lion
how can I achieve this same thing on server side ?