Next.js Discord

Discord Forum

Get current route in App dir

Unanswered
Abyssinian posted this in #help-forum
Open in Discord
AbyssinianOP
I am trying to fetch the route so I can pass it as a prop. I can't use Next/Router as I get this
You have a Server Component that imports next/router. Use next/navigation instead.

How can I do it with next/nav?

4 Replies

so you cant really know the pathname in a server component, the closest you can really get is the referer header but that doesnt work when someone comes to your site from not your website
id say for whatever purpose you need the pathname, make a client component with the new usePathname() function and plug that component in, inside the server component
AbyssinianOP
cool okay ty