I have a client-side component in my next 13 app rendered under the route /journal/October 12, 2023
I cannot figure out how to get the date
from the url. I’ve tried using
import { useRouter } from 'next/navigation';
const router = useRouter;
router.query // this property does not exist in next 13 app directory. this used to exist but only for the pages directory version of next.
I’ve also tried useSearchParams
but that also doesn’t work as that is concerned with query strings.
So what’s going on? Is this a bug or a new feature-gap of Next 13 app directory?
2
Answers
I was able to bypass the hooks by getting the params in the component signature directly, love how incredibly tedious it was to find this, feel like this info absolutely should be co-located in the docs with the other stuff about useRouter but what do I know
To get params from a page you can use
useParams