Pathubs Logo Mark
PATHUBSFREE CAREER ROADMAPS
HomeExploreDiscoverCompare ⚖️My Progress 📊Support
Student Support & Feedback

Have Questions or Need Help?

Have questions, feedback, or suggestions for new roadmaps and interactive tools? Reach out to our team — we review every message to make practical learning better for everyone.

supportpathubs@gmail.com Official Telegram Support (@PathubsSupport)
Pathubs

100% Free, Zero-Paywall Tech Career Roadmaps, In-Depth Practical Content, and Live Interactive Virtual Labs for Learners Worldwide.

Popular Careers

  • Frontend Development
  • Backend Development
  • AI & LLM Engineering
  • Full Stack Web Dev
  • Data Analytics

Platform Tools

  • Career Discovery Quiz
  • Compare Careers

Contact & Info

  • About Us
  • supportpathubs@gmail.com
  • Support Pathubs

© 2026 Pathubs. All Rights Reserved. Structured learning, practical content, and hands-on practice for learners worldwide.

AboutPrivacy PolicyTerms & ConditionsSitemapRobots
Home/Full Stack Development/Frameworks & Architecture/Next.js Basics
NEXT.JS 15.X APP ROUTER⏱️ 60 MIN ESTIMATED✦ FULL-STACK ARCHITECTURE

Next.js Basics — From React to a Full-Stack Framework

Transition from building standalone React client interfaces to architecting scalable, production-grade full-stack web applications. Master the App Router, file-system routing, root & nested layouts, client-side navigation with Link, and the foundational paradigm of Server Components vs. Client Components ("use client").

Curriculum Outline
1Why Next.js? (UI Library vs Framework)2Create a Next.js App (Structure & Dev Server)3App Router & File-System Routing4Layouts & Navigation (Root, Nested, Link)5Server & Client Components ("use client")6Real Next.js Build: Learning Dashboard Lab7Debugging & 5 Common Mistakes8Mini Challenge: Course Portal Architecture9Recap & Final Mental Model10Next.js Basics Mastery Quiz

1. Why Next.js?

The Shift from a Frontend UI Library to a Complete Full-Stack Web Framework

CORE DISTINCTIONLibrary vs Framework

What Next.js Adds Around React

In traditional React, you are working with a UI library. React only provides the component model (UI = fn(state)). When building a complete web application, you were forced to manually stitch together third-party routing libraries (React Router), build tools (Webpack/Vite), data fetching solutions, and SSR servers.

Next.js is the official React framework for full-stack web applications. It wraps React with an opinionated, high-performance architecture:

THE PRACTICAL DIFFERENCE: React ──► UI (Components + JSX + State) Next.js ──► UI + File-System Routing + Layouts + Server Components + Fast Client Navigation + API Endpoints + Production Optimization

With Next.js, your code can run on the server to query databases or fetch data securely, and seamlessly hydrate interactive components in the user's browser without boilerplate.

2. Create a Next.js Application

Project Initialization, Development Server & App Router Directory Structure

PROJECT INITIALIZATION

Creating a Project with create-next-app

The standard, official way to generate a new Next.js application is with the interactive CLI tool:

Terminal / Command PromptBash
# 1. Generate new Next.js application
npx create-next-app@latest my-learning-platform

# Prompts:
✔ Would you like to use TypeScript? Yes
✔ Would you like to use ESLint? Yes
✔ Would you like to use Tailwind CSS? Yes / No
✔ Would you like your code inside a `src/` directory? Yes
✔ Would you like to use App Router? (Recommended) Yes
✔ Would you like to use `@/*` import alias? Yes

# 2. Start the development server
cd my-learning-platform
npm run dev
# -> Server running on http://localhost:3000

Core Project Structure:

my-learning-platform/ ├── app/ # All routes, layouts, and pages (App Router) │ ├── layout.tsx # Root layout (wraps all pages) │ ├── page.tsx # Homepage UI (Route: /) │ └── globals.css # Global stylesheet ├── public/ # Static assets (images, icons, fonts) ├── package.json # Dependencies (next, react, react-dom) ├── next.config.ts # Next.js framework configuration └── tsconfig.json # TypeScript config & path aliases (@/*)

3. App Router & File-System Routing

Folders Define Route Segments; page.tsx Defines Publicly Accessible UI

FILE-SYSTEM CONVENTIONS

How Next.js Translates Folders to URLs

In the App Router, folders define URL route segments, and only the special file page.tsx makes a segment publicly addressable:

FILE-SYSTEM PATH HTTP URL PATH app/page.tsx ──► / app/about/page.tsx ──► /about app/dashboard/page.tsx ──► /dashboard app/courses/page.tsx ──► /courses

Dynamic Segments with Square Brackets [id]

When a route path depends on dynamic data (such as a course ID or slug), wrap the folder name in square brackets:

app/courses/[id]/page.tsxNext.js 15 Async Params
// Route: /courses/react-101 or /courses/42
// In Next.js 15, params is an asynchronous Promise that must be awaited:
export default async function CourseDetailPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;

  return (
    <article>
      <h1>Course: {id}</h1>
      <p>Dynamic route segment resolved on the server.</p>
    </article>
  );
}

4. Layouts & Navigation

Shared UI Hierarchies with layout.tsx and Instant SPA Navigation with Link

SHARED HIERARCHIES

Root Layout vs Nested Layouts

A layout is UI that is shared across multiple pages. When navigating between sibling routes, layouts preserve their component state, avoid unnecessary re-renders, and remain interactive:

Root Layout (app/layout.tsx)

Mandatory root file that defines <html> and <body>. Wraps every page in your application with global headers, footers, and font providers.

Nested Layout (app/dashboard/layout.tsx)

Applies only to routes inside /dashboard/*. Perfect for persistent student sidebars, breadcrumb headers, or tab bars without re-rendering the root layout.

Fast Client-Side Navigation with <Link>

Never use standard HTML <a href="..."> for internal links! Standard anchor tags trigger a full-page browser reload, wiping React state and re-fetching assets. The Next.js <Link> component performs seamless client-side soft navigation with automatic viewport prefetching:

Navigation.tsxNext.js Link
import Link from 'next/link';

export function Navigation() {
  return (
    <nav>
      {/* Prefetched automatically in background when visible in viewport */}
      <Link href="/dashboard">Dashboard</Link>
      <Link href="/courses">All Courses</Link>
    </nav>
  );
}

5. Server & Client Components — Basic Mental Model

Server by Default: When to Run on the Server vs When to Mark "use client"

PARADIGM CORNERSTONE

The Server Components Default

In the App Router, every component is a Server Component by default. They execute exclusively on the server, emitting lightweight HTML/RSC payloads to the browser without shipping their JavaScript dependencies to the client.

Server Components (Default)
  • Direct database access (PostgreSQL, Prisma, SQL queries).
  • Keep private API keys and environment variables safe.
  • Zero JavaScript bundle impact on the client browser.
  • Cannot use useState or event listeners (onClick).
Client Components ("use client")
  • Declared with "use client" at the top of the file.
  • Needed for interactive state: useState, useReducer.
  • Needed for event listeners: onClick, onChange, onSubmit.
  • Needed for browser-only APIs: localStorage, geolocation.
COMPOSITION RULE: Server Component (CoursesPage) ──► Passes data down via props │ ▼ Imports & Renders Client Component (BookmarkButton: "use client") ──► Handles onClick & useState in browser

6. Real Next.js Practical Build — Learning Dashboard

Main Practical Activity: Executable Multi-Route App Router Project with Simulated Browser

INTERACTIVE NEXT.JS APP ROUTER LAB
1. Root app/layout.tsx with global nav
2. Server Component at app/courses/page.tsx
3. Dynamic segment at app/courses/[id]/page.tsx
4. Nested sidebar at app/dashboard/layout.tsx
5. Client boundary at BookmarkButton.tsx
6. SPA transitions using Next.js Link
App Router Files
app/layout.tsxServer Component
http://localhost:3000/
Pathubs

Next.js Full-Stack Portal

Fast client transitions, persistent layouts, and server-side data fetching.

7. Debugging & Common Mistakes

Interactive Anti-Pattern Sandbox: 5 Frequent Pitfalls in Next.js Development

BUG 1Calling useState inside a Server Component
Missing "use client"
// app/courses/page.tsx
// ❌ BROKEN: Server Component trying to use client hooks
import { useState } from 'react';

export default function CoursesPage() {
  const [query, setQuery] = useState(''); // Crashes build / runtime!
  return <input value={query} onChange={e => setQuery(e.target.value)} />;
}
Next.js Compile Error:"You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with 'use client', so they're Server Components by default."
BUG 2Naming Route File about.tsx Instead of about/page.tsx
App Router 404
// File Structure:
app/
├── layout.tsx
├── page.tsx
└── about.tsx  <-- ❌ BROKEN in App Router!

Visiting http://localhost:3000/about returns 404 NOT FOUND!
Symptom: In the legacy Pages Router, pages/about.tsx worked. In the App Router, files directly under app/ (other than page.tsx or layout.tsx) are ignored as route endpoints.
BUG 3Using Standard HTML <a> for Internal Routes
State Wipe & Full Reload
// app/layout.tsx
export default function Navbar() {
  // ❌ BROKEN: Triggers a hard full-page browser refresh!
  return <a href="/dashboard">Dashboard</a>;
}
Consequence: Hard browser refresh destroys in-memory React state, re-executes all root layout scripts, and disables viewport background prefetching.
BUG 4Accessing Synchronous params in Next.js 15
Async Params Warning
// app/courses/[id]/page.tsx (Next.js 15)
// ❌ BROKEN: Treating params as a synchronous object
export default function CoursePage({ params }: { params: { id: string } }) {
  return <h2>Course: {params.id}</h2>;
}
Next.js 15 Warning:"Route /courses/[id] used `params.id`. `params` should be awaited before using its properties."
BUG 5Missing {children} Prop in layout.tsx
Blank Child Pages
// app/layout.tsx
// ❌ BROKEN: Forgetting to output children
export default function RootLayout() {
  return (
    <html>
      <body>
        <header>Global Nav</header>
        {/* Child page.tsx is never rendered! */}
      </body>
    </html>
  );
}
Symptom: Every page in your application displays only the header; the actual page content is completely blank.

8. Mini Challenge: Course Portal Architecture Classifier

Decide: What Belongs on the Server vs What Truly Needs the Client?

ARCHITECTURAL DECISION MATRIX

A key skill of modern Next.js development is knowing whether a feature belongs as a default Server Component or requires an explicit "use client" boundary. Classify each feature below:

1. Course Catalog List (/courses)
Fetches 50 courses from PostgreSQL database and outputs list of static cards with links.
2. Dynamic Course Detail (/courses/[id])
Reads URL param, fetches course syllabus, generates SEO metadata and returns HTML.
3. Video Player with Play/Pause State
Maintains video playback timestamps with useState and responds to player click events.
4. Interactive Quiz Option Checker
Allows students to select option buttons, evaluates answers instantly, and updates score state.
9. Core Summary & Final Mental Model

The complete lifecycle and architectural hierarchy of a modern Next.js full-stack application:

1. Next.js Framework
Wraps React with routing, server execution, optimization, and full-stack capabilities.
2. App Router
Folders define URL route segments. page.tsx defines publicly viewable UI.
3. Layouts
layout.tsx wraps child routes with persistent, shared UI without state wipes.
4. Server Components
Default component model: queries databases securely with zero client bundle impact.
5. Client Components
Marked with "use client" when browser interactivity (useState, onClick) is needed.
6. Link Navigation
Performs instant SPA soft navigation with automatic viewport background prefetching.
THE NEXT.JS FULL-STACK PIPELINE: Browser Request (GET /dashboard) │ ▼ Next.js App Router │ ▼ app/layout.tsx (Root Layout executes on Server) │ ▼ app/dashboard/layout.tsx (Nested Layout executes on Server) │ ▼ app/dashboard/page.tsx (Server Component fetches data) │ ▼ components/BookmarkButton.tsx ("use client" boundary hydrates in browser) │ ▼ Fast, Secure, Interactive Full-Stack Application
TEST YOUR KNOWLEDGE

Next.js Basics Mastery Quiz

Validate your understanding of the App Router, file-system routing, root and nested layouts, Server vs. Client components, and Link prefetching.

Question 1 of 10Score: 0 / 10
What is the fundamental difference between React and Next.js?