Is there a way to get url params inside of server component?
Answered
Cinnamon posted this in #help-forum
CinnamonOP
like context param in
getServerSideProps
on page directory before?Answered by joulev
Use the params and searchParams props: https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional
10 Replies
Answer
CinnamonOP
Awesome! That's exactly what i want thank you 🙇â€â™‚ï¸
Californian
Is it possible to get query params eg
I want to get the category value
http://localhost:3000/about/blog?category=ENGINEERING&DESIGN
from pages folder instead of app folder?I want to get the category value
useRouter
worksCalifornian
Mine doesn't work.
Could you share an example?
Could you share an example?
const router = useRouter()
console.log(router.query)
router.query returns null
it's an empty object when pre-rendering unless you're using SSR (according to the docs)
Check your console in the devtools
@fuma 💙 joulev it's an empty object when pre-rendering unless you're using SSR (according to the docs)
Californian
It is now working on browser console. Thanks!