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 3 of 16

    Dynamic routes

    [slug] and params, searchParams, generateStaticParams, and notFound.

    10 minutes2 games

    You won't make a folder per course. A folder named in square brackets, [slug], matches any value in that URL segment, and the value reaches the page in params.

    TypeScript
    // app/courses/[slug]/page.tsx   matches /courses/react, /courses/sql, …
    import { notFound } from "next/navigation"
    import { getCourse } from "@/lib/courses"
    
    export default async function CoursePage({
      params,
      searchParams,
    }: {
      params: Promise<{ slug: string }>
      searchParams: Promise<{ tab?: string }>
    }) {
      const { slug } = await params            // "react"
      const { tab = "overview" } = await searchParams   // /courses/react?tab=lessons
      const course = await getCourse(slug)
      if (!course) notFound()                  // shows app/not-found.tsx with a 404 status
    
      return <h1>{course.title} · {tab}</h1>
    }

    Important

    Since Next.js 15, params and searchParams are Promises, so you must await them (or use() them in a client component). Older code reading params.slug directly targets Next 14. Also, reading searchParams makes the page dynamic (rendered per request), since its value isn't known at build time.

    FolderMatchesparams

    [slug]

    /courses/react

    { slug: "react" }

    [...parts]

    /docs/a/b/c

    { parts: ["a", "b", "c"] }

    [[...parts]]

    /docs

    { } (optional)

    [slug]/lessons/[id]

    /courses/sql/lessons/4

    { slug: "sql", id: "4" }

    generateStaticParams

    TypeScript
    // Build these course pages ahead of time instead of on each request
    export async function generateStaticParams() {
      const courses = await getAllCourses()
      return courses.map((c) => ({ slug: c.slug }))   // [{ slug: "react" }, { slug: "sql" }, …]
    }

    params values are always strings: id in /lessons/4 is "4", not 4. Convert with Number(id) and check it's a valid number before using it in a query.

    Spot the bug

    This page shows undefined in Next.js 16. Which line?

    Interview question

    When is an App Router page static, and when dynamic?

    Exercise

    Write matchRoute(pattern, url) returning the params object when the URL matches, or null otherwise. Pattern segments in [ ] match any value. Print the results with JSON.stringify.

    Expected output:
    {"slug":"react"}
    {"slug":"sql","id":"4"}
    null
    JavaScript
    function matchRoute(pattern, url) {
      return null
    }
    
    console.log(JSON.stringify(matchRoute("/courses/[slug]", "/courses/react")))
    console.log(JSON.stringify(matchRoute("/courses/[slug]/lessons/[id]", "/courses/sql/lessons/4")))
    console.log(JSON.stringify(matchRoute("/courses/[slug]", "/blog/react")))

    Learn more from

    • Next.js docs: Dynamic route segmentsnextjs.org
    • Next.js docs: generateStaticParamsnextjs.org
    • Vercel docs: Incremental Static Regenerationvercel.com
    • Next.js docs: Upgrading to version 15 (async request APIs)nextjs.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousThe App Router: folders are routesNextClient-side navigation
    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.