Skip to content

Next.js App Router for Beginners: Pages, Layouts, Links and Dynamic Routes

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Next.js is a framework built on React. React draws the interface; Next.js adds what a real website needs around it: one URL per page, HTML that is ready before any JavaScript runs, data loading on the server, and a build that turns it all into fast files. This first lesson covers the part you touch every day, the App Router: the app folder whose folders become URLs. You will create pages, wrap them in a shared layout, link between them, and build one page template that serves many URLs. Next.js runs on a server and a build tool, not inside a browser tab, so the examples here show the files and the real output we recorded by running them with Next.js 16.4.6. Copy them into your own project and you will see the same thing.

Quick answer

In the Next.js App Router, each folder inside app is a URL segment and a page.tsx file inside it makes that URL public: app/shops/page.tsx is /shops. A layout.tsx wraps the pages below it and the root layout must render <html> and <body>. A folder in square brackets, such as app/shops/[city], is a dynamic segment whose value arrives in the params prop, which you await.

35 min read and practice · Content checked on 25 November 2026

In this lesson you will

  • Create a Next.js app and run it with next dev and next build
  • Turn folders into URLs with page.tsx files
  • Share a header and navigation with layout.tsx and Link
  • Build dynamic pages with [segment] folders, params and generateStaticParams

Creating an app and the commands you will use

You need Node.js 20.9 or newer. In a terminal run npx create-next-app@latest my-app and accept the recommended defaults: TypeScript, ESLint, Tailwind CSS, the App Router and Cache Components. The tool creates a folder with app/layout.tsx, app/page.tsx, next.config.ts, tsconfig.json and package.json, and installs next, react and react-dom. The import alias @/* lets you write @/components/Button instead of a long relative path.

Three commands matter. npm run dev starts the development server on http://localhost:3000; it rebuilds as you save and prints each request in the terminal. npm run build makes the production build and prints a table of every route and how it was rendered. npm run start serves that build. Get used to reading the build table early: it tells you which pages are plain static HTML and which need the server at request time, and that decides how fast and how cheap your site is.

The dev terminal below is real. The request line splits the time into the part Next.js spent and the part your own code spent, which helps when a page feels slow. The console.log comes from the page component, and it printed in the terminal, not in the browser, because pages run on the server by default. Lesson 2 explains why.

Example: next dev and one request
app/shops/page.tsx
import Link from "next/link";

export default function ShopsPage() {
  console.log("Rendering ShopsPage");
  return (
    <>
      <h1>Shops by city</h1>
      <ul>
        <li><Link href="/shops/dubai">Dubai</Link></li>
        <li><Link href="/shops/sharjah">Sharjah</Link></li>
      </ul>
    </>
  );
}
Real output: terminal, npm run dev, then opening /shops (port 3101 in our run)
â–² Next.js 16.4.6 (Turbopack)
- Local:         http://localhost:3101
✓ Ready in 436ms
✓ Running next.config.ts took 44ms
- Cache Components enabled
- Partial Prefetching enabled

Rendering ShopsPage
 GET /shops 200 in 422ms (next.js: 227ms, application-code: 195ms)

We started the server on another port because 3000 was busy on our machine, and removed the Network line, which showed our machine address. On yours the address is http://localhost:3000.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What is the difference between the App Router and the Pages Router?

The Pages Router is the older pages folder system. The App Router, in the app folder, is the current one: it supports layouts, Server Components, streaming and Cache Components. New projects should use the App Router, and this course teaches only it.

Which Node.js version does Next.js 16 need?

Node.js 20.9 or newer, on macOS, Windows (including WSL) or Linux. Use a current long-term support release; the examples in this course were recorded with Node.js 22.

Why are the Next.js examples not live like the React ones?

Next.js needs Node.js, a build step and a server, which cannot run safely inside a browser tab. So each example shows the files and the real output we got by running them with a pinned Next.js version. You can paste the same files into your own project and get the same result.

Should I use Link or a plain a tag in Next.js?

Use Link for pages in your own app: it prefetches and swaps pages without a full reload, and it still renders a normal <a href>. Use a plain <a> for other websites and for files you want downloaded.

Can a folder exist in app without becoming a URL?

Yes. A folder is only a public URL when it has a page.tsx or route.ts. Folders in parentheses are route groups left out of the URL, and folders starting with an underscore are private.

Sources

Facts in this lesson were checked against these official pages on 25 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.