I am currently learning next and I am confused as to how to implement dynamic routing.
Here is what I am doing:
"use client"
import React from "react";
import { useRouter } from "next/router";
const ID = () => {
const router = useRouter();
return <div>{router.query.id}</div>;
};
export default ID;
Some resources claim that the dynamic route,name [], should be in the name of the folder. Other, like the documentation, claim it should be the file. How to make dynamic routes work in Next.js?
2
Answers
for dynamic routes in nextjs, the parent folder is in brackets while there is a page.tsx in the folder. As you are using nextjs 13. Previous versions of Nextjs dynamic routes could be handled with your routing.
Solution:
check/[id]/page.tsx
., the parent folder is in brackets while there is a page in the folderCreate one more folder in your check folder
[id]
and then create page.tsx inside of the folder and add the following code: