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?

10 Replies

Avatar
joulev
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
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
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!