Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    NNext.js

    Next.js foundations

    • What is Next.js?
    • The App Router: folders are routes
    • Dynamic routes
    • Client-side navigation

    Server, client and data

    • Server and Client Components
    • Fetching data on the server
    • loading, error and not-found
    • Caching and revalidation

    Mutations, APIs and security

    • Server Actions
    • Route Handlers: building an API
    • Proxy (formerly Middleware)
    • Authentication and protecting pages

    Going to production

    • Metadata and SEO
    • Images, fonts and performance
    • Environment variables and deploying to Vercel
    • Project: a course catalogue
    Next.js

    Next.js foundations · Lesson 2 of 16

    The App Router: folders are routes

    page and layout, nested routes, Link, and route groups.

    9 minutes3 games

    Next.js has no routes config file. Each folder inside `app/` is a URL segment, and a folder containing page.tsx becomes a page people can visit.

    • app/
      • layout.tsx → wraps every page
      • page.tsx → /
      • courses/
        • page.tsx → /courses
        • layout.tsx → wraps /courses/*
        • react/page.tsx → /courses/react
      • (marketing)/about/page.tsx → /about
      • _components/ → not a route

    A folder in brackets (marketing) organizes files without appearing in the URL, and one starting with _ is excluded from routing.

    TypeScript
    // app/layout.tsx: the root layout, required, renders <html> and <body>
    import type { ReactNode } from "react"
    import Link from "next/link"
    
    export default function RootLayout({ children }: { children: ReactNode }) {
      return (
        <html lang="en">
          <body>
            <nav>
              <Link href="/">Home</Link> · <Link href="/courses">Courses</Link>
            </nav>
            {children}   {/* the current page goes here */}
          </body>
        </html>
      )
    }

    A layout wraps the pages below it and doesn't re-render when you navigate between them, so its state (like a sidebar input) is preserved. Layouts nest: app/layout.tsx wraps app/courses/layout.tsx, which wraps app/courses/react/page.tsx.

    Important

    Use <Link> from next/link for internal links, not a plain <a>: it navigates without a full page reload and prefetches pages whose links are visible, so navigation feels instant. Plain <a> is for external links only.

    Order the lines

    Order the layouts and page from outermost to innermost when opening /courses/react.

    1. Click the lines in the right order

    Quick question

    You want a page at /settings/profile. Where does the file go?

    Interview question

    What's the difference between layout.tsx and template.tsx?

    Exercise

    Write routeFor(file) that turns a file path into a URL the way Next.js does: drop app and page.tsx, and drop folders in brackets. Print the result for the three files in the code.

    Expected output:
    /
    /courses/react
    /about
    JavaScript
    function routeFor(file) {
      // "app/(marketing)/about/page.tsx" -> "/about"
      return file
    }
    
    console.log(routeFor("app/page.tsx"))
    console.log(routeFor("app/courses/react/page.tsx"))
    console.log(routeFor("app/(marketing)/about/page.tsx"))

    Learn more from

    • Next.js docs: Layouts and pagesnextjs.org
    • Next.js docs: Linking and navigatingnextjs.org
    • Next.js docs: Route groupsnextjs.org
    • Vercel blog: Understanding React Server Componentsvercel.com

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousWhat is Next.js?NextDynamic routes
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.