1. What is Next.js?
BeginnerAnswer: React framework for production with SSR and SSG
Next.js is a React framework that provides server-side rendering, static site generation, routing, and other production features out of the box.
24 questions that come up in Next.js technical interviews, each with the answer and an explanation of why it is right.
Test yourself — 90 question bankAnswer: React framework for production with SSR and SSG
Next.js is a React framework that provides server-side rendering, static site generation, routing, and other production features out of the box.
Answer: New routing based on app directory with Server Components
App Router (Next.js 13+) uses app directory with React Server Components, streaming, nested layouts. Co-exists with pages router.
Answer: Create file in pages/api with handler function
Create a file in pages/api. Export default function: export default function handler(req, res) { res.status(200).json() }.
Answer: Components marked with 'use client' directive
Client Components use client JS and interactivity. Mark with 'use client' directive at top. Required for hooks, events, browser APIs.
Answer: Shared UI wrapping route segments in App Router
layout.js in App Router wraps route segments. Nested layouts possible. State preserved during navigation. Root layout wraps entire app.
Answer: Routes with parameters using [param] syntax
Dynamic routes use [param] syntax. pages/post/[id].js matches /post/1, /post/2, etc. Access via useRouter or context.params.
Answer: Use [...slug].js
Catch-all routes use [...slug].js. Matches /post/a, /post/a/b, /post/a/b/c. params.slug is array. Optional: [[...slug]].js.
Answer: Customizes HTML document structure
_document.js customizes the HTML document structure (html, head, body tags). Used for custom fonts, meta tags, and scripts.
Answer: Error boundary wrapping route segments
error.js defines error boundary for route segment. Catches errors in Server Components. Must be Client Component with 'use client'.
Answer: Use Link component from next/link
Use the Link component from next/link for client-side navigation: <Link href="/about">About</Link>. Provides prefetching.
Answer: Progressively renders UI as it becomes ready
Streaming progressively renders and sends UI to client as it becomes ready. Improves perceived performance. Built into App Router.
Answer: Shows fallback while async component loads
Suspense shows fallback UI while async component loads. Enables streaming and granular loading states. Core to App Router.
Answer: Use router.push()
Use router.push('/path') for programmatic navigation. router.replace() for replacing history. Get router from useRouter().
Answer: Route organization without affecting URL using (folder)
Route Groups organize routes without affecting URL. Use (folder) syntax. Example: (marketing) and (shop) groups, but URLs have no prefix.
Answer: Static Site Generation
SSG (Static Site Generation) pre-renders pages at build time. HTML generated once, reused on each request. Best for performance.
Answer: Server-Side Rendering
SSR (Server-Side Rendering) generates HTML on each request on the server. Fresh data on every request but slower than SSG.
Answer: Seconds to wait before regenerating page (ISR)
revalidate in getStaticProps enables ISR. Value is seconds to wait before regenerating: revalidate: 60 regenerates at most once per minute.
Answer: Renders multiple pages in same layout simultaneously
Parallel routing renders multiple pages simultaneously in same layout. Use @folder slots. Enables complex layouts like dashboards.
Answer: Custom request handlers like API routes
Route handlers are custom request handlers in app directory. Use route.js with GET, POST, etc. exports. Replaces API routes.
Answer: Changes URL without re-running data fetching
Shallow routing changes URL without re-running getStaticProps, getServerSideProps. Use router.push(url, as, { shallow: true }).
Answer: Controls behavior for paths not generated at build
fallback controls non-pre-rendered paths. false: 404. true: render fallback then static. 'blocking': wait for generation. Used with getStaticPaths.
Answer: SEO metadata defined via metadata object or generateMetadata
Metadata defines SEO tags via metadata object or generateMetadata function. Automatically merges and deduplicates. Replaces Head component.
Answer: URL redirects configured in next.config.js
Redirects in next.config.js map old paths to new ones. Support permanent and temporary redirects. Example: redirects: async () => [{ source, destination, permanent }].
Answer: Map URLs to different destinations without changing browser URL
Rewrites proxy requests to different URLs without browser seeing it. Configured in next.config.js. Useful for API proxying.
The full Next.js bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.
Take the Next.js quiz