Next.js is the most popular React framework for production apps. These Next.js interview questions cover routing, pages and rendering basics for freshers, then the App Router, Server Components, data fetching and caching, Server Actions, middleware, SEO and deployment for experienced Next.js developers.
30 questions · Updated
Reading answers is not the same as saying them.Practise Next.js questions out loud and get a score, what you missed and a model answer for each one.
Practise free with AINext.js Interview Questions: 30 questions with model answers on this page.
Basic Next.js interview questions
Fundamentals, definitions and simple scenarios. Good for freshers and warm-ups.
1. What is Next.js, and why use it instead of plain React?
Answer flow · 3 steps
1
Next.js is a React framework that adds file-based routing, server-side rendering, static generation, API routes, image and font optimisation, and production build tooling.
2
Plain React (for example with Vite) renders in the browser only.
3
Next.js gives faster first loads, better SEO and a full-stack structure without configuring these pieces yourself.
2. What is the difference between the Pages Router and the App Router?
Answer flow · 3 steps
1
The Pages Router uses the pages folder, with getServerSideProps, getStaticProps and getStaticPaths for data.
2
The App Router, introduced in Next.js 13, uses the app folder with nested layouts, React Server Components by default, streaming with loading.js, and data fetched directly in async components.
3
The App Router is recommended for new projects.
3. How does routing work in the App Router?
Folders define routes and a page.js file makes the route public, so app/blog/page.js serves /blog. Dynamic segments use brackets, such as app/blog/[slug]/page.js. layout.js wraps child routes and keeps state across navigation, loading.js shows a loading state, error.js handles errors, and route groups in parentheses organise files without affecting the URL.
4. How do you create a Next.js app, and what is its folder structure?
Run npx create-next-app@latest and choose TypeScript, ESLint, Tailwind and the App Router. The app folder holds routes, with layout.js and page.js files; public holds static files served from the root; next.config.js holds configuration; and components and lib folders are common conventions. npm run dev starts the development server.
5. What does the Link component do?
Answer flow · 3 steps
1
next/link's Link component navigates between pages on the client without a full page reload, keeping layouts and state.
2
In production it automatically prefetches the code and data for links visible in the viewport, so navigation feels instant.
3
Use it for internal links and a normal <a> tag for external sites.
6. What are layouts and templates?
Answer flow · 3 steps
1
A layout.js wraps a route segment and its children, and stays mounted when navigating between child pages, so state and shared UI such as navigation persist.
2
The root layout must contain the html and body tags.
3
A template.js is similar but creates a new instance on every navigation, which suits enter animations or resetting state.
7. What do loading.js and error.js do?
loading.js shows an instant loading UI for a route segment while its content loads, using React Suspense, so users see feedback immediately. error.js is a client component that catches errors in that segment and shows a fallback with a reset button, without breaking the rest of the page. not-found.js handles 404 states, and global-error.js handles errors in the root layout.
8. How do dynamic routes and generateStaticParams work?
A folder in square brackets, such as app/blog/[slug]/page.js, matches any value, which the page receives through params. [...slug] catches all remaining segments. generateStaticParams returns the list of params to pre-render at build time, so those pages are static; setting dynamicParams = false returns 404 for any other value.
9. How do environment variables work in Next.js?
Answer flow · 4 steps
1
Variables in .env files are loaded automatically, with .env.local for secrets that are not committed.
2
By default they are only available on the server.
3
Only variables prefixed with NEXT_PUBLIC_ are included in the browser bundle, so secrets such as API keys must never use that prefix.
4
Variables are set per environment in the hosting dashboard.
10. How do you handle static files and fonts?
Files in the public folder are served from the site root, so public/logo.png is available at /logo.png. Special files such as favicon.ico, icon.png and robots.txt can go in the app folder. next/font downloads Google or local fonts at build time and self-hosts them, with no layout shift and no requests to Google from the browser.
11. What are route handlers?
Answer flow · 3 steps
1
Route handlers are API endpoints in the App Router, defined in a route.js file that exports functions named after HTTP methods, such as GET and POST, using the standard Request and Response objects.
2
They are used for webhooks, APIs for mobile apps and third parties, and generated files such as RSS feeds.
3
For mutations from your own forms, Server Actions are often simpler.
Intermediate Next.js interview questions
Applied problems, trade-offs and questions about your own projects.
12. What are Server Components and Client Components in Next.js?
Answer flow · 3 steps
1
In the App Router, components are Server Components by default: they render on the server, can fetch data and access secrets directly, and send no JavaScript to the browser.
2
Adding "use client" at the top of a file makes it a Client Component, needed for state, effects, event handlers and browser APIs.
3
The best practice is to keep client components small and at the leaves of the tree.
13. Explain SSR, SSG and ISR.
Answer flow · 3 steps
1
Server-side rendering builds the HTML on each request, which suits personalised or frequently changing pages.
2
Static site generation builds pages at build time and serves them from a CDN, which is fastest.
3
Incremental static regeneration rebuilds static pages in the background after a set time or on demand with revalidatePath or revalidateTag, combining static speed with fresh data.
14. How does next/image help performance?
The Image component automatically resizes images to the right size for each device, serves modern formats such as WebP or AVIF, lazy-loads images below the fold, and requires dimensions or fill to prevent layout shift. The priority prop preloads the main hero image to improve Largest Contentful Paint.
15. How do you handle SEO in Next.js?
In the App Router I export a metadata object or generateMetadata function from pages and layouts to set titles, descriptions, canonical URLs and Open Graph tags. sitemap.js and robots.js generate those files, opengraph-image can generate share images, and JSON-LD structured data is added with a script tag. Server rendering means crawlers get full HTML.
16. How do you fetch data in Server Components?
Answer flow · 4 steps
1
Server Components can be async and fetch data directly with fetch or a database client, without useEffect or an API layer.
2
Independent requests should start together with Promise.all to avoid waterfalls, while dependent requests run in order.
3
Wrapping slower parts in Suspense lets the rest of the page show first.
4
Sensitive code can be protected with the server-only package.
17. What is streaming in Next.js?
Answer flow · 3 steps
1
Streaming sends the page to the browser in chunks as they become ready instead of waiting for all data.
2
The layout and fast parts appear immediately, and slower sections wrapped in Suspense (or covered by loading.js) show a fallback and then stream in.
3
This improves time to first byte and how fast the page feels, especially with slow APIs.
18. What are parallel and intercepting routes?
Parallel routes, created with named slots such as @analytics, render several pages in the same layout at once, each with its own loading and error states, which suits dashboards. Intercepting routes, using conventions like (.)photo/[id], show a route inside the current layout, for example opening a photo in a modal from a feed, while a direct visit to the URL shows the full page.
19. How do redirects and rewrites work?
Answer flow · 3 steps
1
Permanent redirects for moved pages can be listed in next.config.js under redirects, or done in code with redirect() and permanentRedirect() from next/navigation in Server Components and Server Actions.
2
Rewrites map a URL to a different path without changing what the user sees, for example proxying /api to another server.
3
Middleware (proxy) can redirect conditionally, such as by locale.
20. How do you implement authentication in Next.js?
Answer flow · 4 steps
1
Use a library such as Auth.js (NextAuth), Clerk or Supabase Auth, or your own sessions in HttpOnly cookies.
2
Check the session on the server in layouts, pages, Server Actions and route handlers, because middleware alone is not enough for security.
3
Middleware can redirect unauthenticated users early for a better experience.
4
Keep authorisation checks next to the data access.
21. How do you read the URL in client components?
next/navigation provides hooks for client components: useRouter for navigating programmatically (push, replace, refresh, back), usePathname for the current path, useSearchParams for query string values, and useParams for dynamic route parameters. Server Component pages receive params and searchParams as props instead.
22. What is the difference between the Edge and Node.js runtimes?
Answer flow · 3 steps
1
The Node.js runtime has full access to Node APIs and npm packages and is the default.
2
The Edge runtime runs on lightweight servers close to users with very fast start-up, but supports only a subset of APIs, so many Node libraries and database drivers do not work.
3
Edge suits simple, latency-sensitive logic; most pages and APIs should use Node.js.
High level Next.js interview questions
System design, deep internals, leadership and tough follow-ups.
23. How does caching work in the App Router?
Answer flow · 3 steps
1
Next.js has several layers: request memoisation removes duplicate fetches during one render, the data cache stores fetch results across requests, the full route cache stores rendered static routes, and the router cache stores visited routes in the browser.
2
Next.js 15 changed fetch and GET route handlers to be uncached by default.
3
You opt in with cache options, revalidate settings or the "use cache" directive, and invalidate with revalidatePath and revalidateTag.
24. What are Server Actions?
Answer flow · 3 steps
1
Server Actions are async functions marked with "use server" that run on the server but can be called directly from forms and client components, for example <form action={createPost}>.
2
They remove the need to write separate API routes for mutations, work with progressive enhancement, and can revalidate cached data after a change.
3
Inputs must still be validated and the user authorised, because they are public endpoints.
25. What is middleware in Next.js, and what is it used for?
Answer flow · 3 steps
1
Middleware (middleware.js at the project root, renamed proxy.js in Next.js 16) runs before a request is completed.
2
It can rewrite, redirect or modify headers based on the request, which suits authentication checks, refreshing sessions, redirects by locale or geography, A/B testing and bot protection.
3
It should stay fast and light, using a matcher to run only on routes that need it.
26. What is Partial Prerendering?
Answer flow · 3 steps
1
Partial Prerendering combines static and dynamic rendering in one route.
2
The static shell of the page is served instantly from the edge like a static site, while dynamic parts wrapped in Suspense, such as a personalised cart, are streamed in the same response.
3
In Next.js 16 this is part of Cache Components, where you mark cacheable parts with "use cache".
27. How can you deploy a Next.js application?
Vercel supports every feature with no configuration. Next.js can also be self-hosted as a Node.js server with next start, packaged as a small Docker image using output: "standalone", deployed to other platforms such as Netlify, AWS Amplify or Cloudflare through adapters, or exported as a fully static site with output: "export" if it uses no server features.
28. How do you improve performance in a Next.js app?
Keep most components as Server Components so less JavaScript ships, push "use client" down to small interactive leaves, use next/image and next/font, lazy-load heavy client components with next/dynamic, avoid data waterfalls, cache data where it is safe, and stream slow sections. I check bundles with @next/bundle-analyzer and measure Core Web Vitals from real users.
29. How do you keep server code and secrets safe in Next.js?
Keep secrets in environment variables without the NEXT_PUBLIC_ prefix, import the server-only package in modules that must never reach the browser, and be careful what props you pass from Server to Client Components, since they are sent to the browser. Treat Server Actions as public endpoints: validate input, check authentication and authorisation in every action, and use a data access layer.
30. How do you migrate from the Pages Router to the App Router?
Answer flow · 3 steps
1
Both routers can run in the same app, so migration can be gradual, route by route.
2
Move _app and _document into the root layout, convert getServerSideProps and getStaticProps into data fetching inside async Server Components, replace getStaticPaths with generateStaticParams, swap next/router for next/navigation hooks, and add "use client" to components that use state or browser APIs.
3
Test each route as you move it.
Ready to test yourself?Pick your topics and level, answer by voice or text, and get instant feedback. Free.