getting page router within server component
Unanswered
American black bear posted this in #help-forum
American black bearOP
hello, I have a navbar which is being rendered on the serverside. As part of this navbar I need to highlight the active page they are on. However, I'm not sure how I can do this on the server as the
useRouter hook is not available. Does anybody have any idea? I'm using next app router.10 Replies
Or just make a sub component inside your server component that’s client side
@Jboncz https://www.propelauth.com/post/getting-url-in-next-server-components
i think its better to just do parallel routes or your second suggestion of client instead of this "abuse"
that isn't really abuse. that's just forcing the entire app to dynamic rendering which is 99% of the time a horrible idea.
Huh? Setting a header in middleware? Did I link the wrong article?
seeing the og image of the article is enough for me to know that it's writing something wrong, honestly
there is no such thing as "getting the current URL in server components". do it in client components.
American black bearOP
thank you 🙂
https://spacejelly.dev/posts/how-to-style-active-links-in-next-js-app-router
yeah, your navbar can be client component @Donskoy
yeah, your navbar can be client component @Donskoy