What is the purpose of the app directory in Next.js App Router?
The app directory organizes your application’s UI and routing using React Server Components. It replaces the older pages directory and allows for nested layouts, server rendering, and improved routing control.
Click to reveal answer
beginner
How do you define a route in the Next.js app directory?
Each folder inside the app directory corresponds to a route segment. A file named page.jsx or page.tsx inside a folder defines the component rendered for that route.
Click to reveal answer
intermediate
What is a layout in the Next.js App Router and how is it used?
A layout is a React component named layout.jsx or layout.tsx inside a folder in app. It wraps pages and nested routes, allowing shared UI like headers or footers to persist across pages.
Click to reveal answer
intermediate
Explain the difference between Server Components and Client Components in the Next.js App Router.
Server Components run on the server and can fetch data directly, improving performance. Client Components run in the browser and handle interactivity. You mark Client Components with "use client" at the top of the file.
Click to reveal answer
intermediate
How does Next.js handle loading states in the App Router?
You can create a loading.jsx or loading.tsx file inside a route folder to show a loading UI while the page or data is loading. This improves user experience by showing feedback during navigation.
Click to reveal answer
In Next.js App Router, which file defines the UI for a route?
Aroute.js
Bpage.jsx
Capp.js
Dindex.js
✗ Incorrect
The page.jsx file inside a folder in the app directory defines the UI for that route.
What file do you add to share UI like headers across multiple pages in Next.js App Router?
Ashared.jsx
Bheader.jsx
Clayout.jsx
Dapp.jsx
✗ Incorrect
The layout.jsx file wraps pages and nested routes to share UI elements like headers or footers.
How do you mark a component as a Client Component in Next.js App Router?
AUse a special ClientComponent wrapper
BName the file client.jsx
CImport React from 'client'
DAdd "use client" at the top of the file
✗ Incorrect
Adding "use client" at the top of the file marks it as a Client Component.
Where do you place a loading.jsx file in Next.js App Router?
AInside the route folder to show loading UI for that route
BIn the root <code>app</code> directory only
CNext to <code>page.jsx</code> but outside any folder
DIn the <code>public</code> folder
✗ Incorrect
Placing loading.jsx inside a route folder shows a loading UI while that route is loading.
What is the main advantage of Server Components in Next.js App Router?
AThey run on the server and can fetch data directly
BThey run faster in the browser
CThey allow client-side routing
DThey enable CSS styling
✗ Incorrect
Server Components run on the server and can fetch data directly, improving performance and reducing client bundle size.
Describe how routing works in the Next.js App Router using the app directory structure.
Think about how folders and files map to URLs and UI.
You got /4 concepts.
Explain the difference between Server Components and Client Components in Next.js App Router and when to use each.
Consider where the code runs and what it does.
You got /5 concepts.
Practice
(1/5)
1. In Next.js App Router, what does a folder containing a page.js file represent?
easy
A. A route in the application
B. A layout wrapper for pages
C. A server API endpoint
D. A static asset folder
Solution
Step 1: Understand the role of page.js in App Router
In Next.js App Router, each folder with a page.js file defines a route that users can visit.
Step 2: Differentiate from other files
Files like layout.js define layouts, not routes. API routes are in api/ folders, and static assets are in public/.
Final Answer:
A route in the application -> Option A
Quick Check:
Folder + page.js = route [OK]
Hint: Folder with page.js always means a route [OK]
Common Mistakes:
Confusing layout.js with page.js
Thinking page.js is for API routes
Assuming static assets are routes
2. Which of the following is the correct way to define a layout in the Next.js App Router?
easy
A. Create a layout.js file inside the route folder
B. Create a page.js file inside the route folder
C. Create a _app.js file in the root folder
D. Create a server.js file in the route folder
Solution
Step 1: Identify layout file naming in App Router
Layouts are defined by creating a layout.js file inside the folder representing the route.
Step 2: Exclude old or unrelated files
The _app.js file is used in the old pages router, not App Router. page.js defines pages, not layouts. server.js is unrelated.
Final Answer:
Create a layout.js file inside the route folder -> Option A
Quick Check:
layout.js = layout file [OK]
Hint: Layouts use layout.js, not page.js or _app.js [OK]
Common Mistakes:
Using _app.js instead of layout.js
Confusing page.js with layout.js
Trying to define layout in server.js
3. Given this folder structure in the app/ directory: