I am using a dynamic router in Next.js, and this is the code
import { useRouter } from "next/router";
const exampleFunction = () => {
const router = useRouter();
const {slug} = router.query;
console.log(slug);
return (
<h1>{slug}</h1>
);
};
export default exampleFunction;
The location of the file is:
lms/client/pages/teacher/course/test/[slug].js
When I access the link like this:
http://localhost:3000/teacher/course/test/testmw
I can see the slug is being rendered in the browser; however when I look at the console, I see undefined
value before the actual value of the slug.
I wonder this is something I've done wrong or this is the expected behavior of Next.js?
I've been suggested a similar question. However, the answer is mostly about getting the route in server-side, I wonder if I can effectively do the same thing on the client-side.