Next.js Discord

Discord Forum

Is there a way to get url params inside of server component?

Answered
Cinnamon posted this in #help-forum
Open in Discord
Avatar
CinnamonOP
like context param in getServerSideProps on page directory before?
Answered by joulev & fuma pray for Schneider
View full answer

10 Replies

Avatar
joulev & fuma pray for Schneider
Answer
Avatar
CinnamonOP
Awesome! That's exactly what i want thank you 🙇‍♂️
Avatar
Californian
Is it possible to get query params eg http://localhost:3000/about/blog?category=ENGINEERING&DESIGN from pages folder instead of app folder?
I want to get the category value
Avatar
fuma & joulev pray for Schneider
useRouter works
Avatar
Californian
Mine doesn't work.
Could you share an example?
const router = useRouter() console.log(router.query)


router.query returns null
Avatar
fuma & joulev pray for Schneider
it's an empty object when pre-rendering unless you're using SSR (according to the docs)
Check your console in the devtools
Avatar
Californian
It is now working on browser console. Thanks!