Query parameter in dynamic route is undefined on first render #21533
|
What version of Next.js are you using? 10.0.6-canary.7 What version of Node.js are you using? 14.15.4 What browser are you using? Chrome What operating system are you using? macOS How are you deploying your application? next dev Describe the Bug When creating a dynamic route e.g. Expected Behavior The initial render should contain the URL parameter. To Reproduce With an empty app as created by import React from "react";
import { useRouter } from "next/router";
export const Page = () => {
const router = useRouter();
console.log(router);
return (
<div>Hello!</div>
);
};
export default Page;Then load http://localhost:3000/foo. There will be two console log lines, |
Replies: 1 comment 4 replies
|
You can use https://nextjs.org/docs/api-reference/next/router#router-object This behavior is expected, per these docs: https://nextjs.org/docs/routing/dynamic-routes#caveats
|
You can use
router.isReadyto determine when therouter.queryvalue is available.https://nextjs.org/docs/api-reference/next/router#router-object
This behavior is expected, per these docs: https://nextjs.org/docs/routing/dynamic-routes#caveats