0

I am using Next.js Here is my file structure:

--courses  (folder)
 -course.js  (file)
  --chapters   (folder)
    -[chapter].js   (file)

I have a chapter called "hello-world" which will be in [chapter].js

I want the route to be as follows:

<Link href={"/courses/chapters/hello-world?section=10"}>Hello World</Link>

I want the [chapter].js file to be used by multiple pages/components. In the [chapter].js file, when I say:

const router = useRouter();

console.log("router params: ", router.query);

I get the following: hello-world

I do not get section = 10

I want to be able to get the hello-world page that will be served from [chapter].js and also get the section=10 URL param.

Thanks.

Martinez
  • 1,109
  • 1
  • 4
  • 13
abc
  • 11
  • 3

1 Answers1

0

Use this code:

var router = useRouter();
var section = router.query["section"];
Sowmo0509
  • 54
  • 7