Next.js Discord

Discord Forum

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

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

14 Replies

Avatar
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
Avatar
SiberianOP
can you give an example with useParams? i just have ssomething like this
Image
Avatar
it looks like you don't have a dynamic fragment. Why do you want to get the shrubs?
Avatar
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
Avatar
ok, but when you are on the page shrubs then you already know, that you are on the page 🤔
Avatar
SiberianOP
yeah but the searchbar component doesnt belong to the shrubs component
its seperate
        <SearchProvider>
       <Provider>
        <Navbar/>
        {children}
        </Provider>
        </SearchProvider> 
here is the markup
Avatar
ah ok, then you can use the hook usePathname() to retrieve the full pathname
Answer
Avatar
SiberianOP
thank you 🙂
it works
Avatar
happy to help
Avatar
Barbary Lion
how can I achieve this same thing on server side ?