Routing in Next.js

Last Updated :
Discuss
Comments

Question 1

How do you get the current route (pathname) in Next.js App Router?

  • useRouter().pathname

  • usePathname()

  • router.query

  • window.location.pathname

Question 2

In Next.js Pages Router, which hook provides the current route?

  • useRouter().pathname

  • window.location

  • router.query.route

  • usePathname()

Question 3

How do you create a catch-all route in Pages Router?

  • [id].js

  • [[...slug]].js

  • _catch.js

  • [...slug].js

Question 4

What’s the correct syntax for an optional catch-all route?

  • [slug].js

  • _optional.js

  • [...slug].js

  • [[...slug]].js

Question 5

Which statement is true about [...slug] vs [[...slug]]?

  • [...slug] requires at least one param, [[...slug]] makes it optional

  • [...slug] is for API routes only

  • Both require at least one param

  • Both make params optional

Question 6

How are nested routes created in App Router?

  • By _app.js file

  • By editing next.config.js

  • By using <Route> tags

  • By creating nested folders inside app/

Question 7

Which file is required inside each App Router folder to render a route?

  • _app.js

  • _document.js

  • index.html

  • page.js

Question 8

How do you define a dynamic API route in Next.js?

  • pages/api/[id].js

  • api/routes.js

  • pages/[api]/[id].js

  • app/api/[id]/page.js

Question 9

How do you access a dynamic param in API routes?

  • req.params.id

  • context.params.id

  • useRouter().query.id

  • req.query.id

Question 10

How do you define a dynamic segment in App Router?

  • app/id/page.js

  • app/[id]/page.js

  • app/routes/[id].js

  • pages/[id].js

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion