React / Next.js

Next.js Routing & Navigation

Dynamic routes, route groups, parallel routes, intercepting routes, useRouter, Link, redirect

22 interview questionsยท
Mid-Level
1

What is the syntax to create a dynamic route in Next.js App Router?

Answer

Dynamic routes in Next.js App Router use square brackets to define variable URL segments. For example, [id] creates a route that captures any value at that position in the URL. This value is then accessible via the page parameters. This convention allows creating generic pages that adapt to different content without creating separate files for each variation.

2

What is the primary role of the Link component in Next.js?

Answer

The Link component is the recommended navigation element in Next.js. It automatically prefetches visible routes in the viewport and enables client-side navigation without full page reloads. Unlike a standard a tag, Link maintains application state and provides smooth transitions between pages, significantly improving user experience and performance.

3

How to access dynamic route parameters in a Server Component?

Answer

In Next.js App Router, Server Components automatically receive a params object containing the dynamic URL segments. This object is passed as a prop to the component function. For example, for a [id] route, params.id will contain the captured value. This approach simplifies parameter access without needing client-side hooks.

4

What is the main advantage of route groups in Next.js?

5

What is the difference between useRouter and usePathname?

+19 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free