Skip to content
Qyubie Learn
Web Development courseLesson 14 of 20 · tap to see all lessons

Web Development · Beginner

Next.js, Tailwind CSS, and Watermelon UI: App Router, Layouts, Dynamic Routes, and Pull Requests

Build a multi-page site with the Next.js App Router, style it with Tailwind CSS and breakpoints, add Watermelon UI components, and collaborate with pull requests.

  • Qyubie Learn Editorial Team
  • Published
  • 19 min read

Includes 1 exercise and 3 quick checks you can do right here.

React (lessons 12 and 13) builds components, but a website needs more: many pages with their own URLs, shared layouts, a server, and a build for production. Next.js is a React framework that provides all of that, and it's what this course uses for the final project. In this lesson you'll set up a Next.js app, build pages, layouts, and dynamic routes, style everything with Tailwind CSS, add ready-made components from Watermelon UI, and learn how teams combine their work with pull requests.

By the end of this lesson you will be able to:

  • create a Next.js project and explain its folder structure,
  • build pages, layouts, nested routes, and navigation with the App Router,
  • create dynamic routes and read route parameters,
  • style pages with Tailwind CSS utilities and responsive breakpoints,
  • add Watermelon UI components and keep a design consistent, and
  • collaborate on GitHub with branches and pull requests.

Creating a Next.js project

You need Node.js 20.9 or newer (check with node -v). Then run:

npx create-next-app@latest class-portal

It asks for a project name, then: "Would you like to use the recommended Next.js defaults?" Choose "Yes, use recommended defaults". That gives you TypeScript, ESLint, Tailwind CSS, the App Router, and the @/* import alias, which is exactly the setup this lesson uses. (To skip the questions entirely, add --yes.)

Start the development server:

cd class-portal
npm run dev

Open http://localhost:3000. Edit app/page.tsx, save, and the browser updates immediately.

The project structure

The files that matter most:

class-portal/
├── app/                 ← your pages and layouts (the App Router)
│   ├── layout.tsx       ← root layout: wraps every page
│   ├── page.tsx         ← the home page, at /
│   └── globals.css      ← global styles; imports Tailwind
├── public/              ← images and files served as-is (public/logo.png → /logo.png)
├── next.config.ts       ← Next.js settings
├── package.json         ← scripts: dev, build, start
└── tsconfig.json        ← TypeScript settings

The .tsx files are TypeScript with JSX. TypeScript is JavaScript plus type labels, such as { id: string }, that catch mistakes before you run the code. Everything you learned in React works the same; the labels are extra.

Pages and routing

The App Router uses folders as routes. A folder inside app/ becomes a URL segment, and a page.tsx file inside it is the page shown at that URL:

FileURL
app/page.tsx/
app/about/page.tsx/about
app/students/page.tsx/students
app/students/[id]/page.tsx/students/1, /students/2, ...

A page is just a React component exported as the default export:

// app/page.tsx
export default function HomePage() {
  return (
    <section>
      <h1 className="text-3xl font-bold">Welcome to BSCS 3A</h1>
      <p className="mt-2 text-gray-600">Find your classmates and subjects here.</p>
    </section>
  );
}
// app/about/page.tsx
export default function AboutPage() {
  return <h1 className="text-2xl font-bold">About this portal</h1>;
}

Create the about folder and file, save, and /about exists. No router setup needed. (The className values are Tailwind classes, explained below.)

Layouts and navigation

A layout wraps pages with UI they share, like a navigation bar. It receives the page as children (the prop from lesson 12). The root layout, app/layout.tsx, is required and must contain the <html> and <body> tags:

// app/layout.tsx
import type { Metadata } from "next";
import Link from "next/link";
import "./globals.css";

export const metadata: Metadata = {
  title: "Class Portal",
  description: "Subjects and students of BSCS 3A",
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body className="bg-gray-50 text-gray-900">
        <nav className="flex gap-4 border-b bg-white px-6 py-3">
          <Link href="/" className="font-bold">Class Portal</Link>
          <Link href="/students">Students</Link>
          <Link href="/about">About</Link>
        </nav>
        <main className="mx-auto max-w-4xl p-6">{children}</main>
      </body>
    </html>
  );
}
  • metadata sets the page <title> and description for browsers and search engines.
  • Link from next/link is how you navigate between your own pages. It works like <a href>, but switches pages without a full reload and preloads pages the user is likely to open. Use a plain <a> only for other websites.
  • When the user moves between pages, the layout stays: the nav isn't rebuilt, only {children} changes.

Nested routes and nested layouts

Folders can nest, and so can layouts. A layout.tsx inside app/students/ wraps only the pages under /students, inside the root layout:

// app/students/layout.tsx
export default function StudentsLayout({ children }: { children: React.ReactNode }) {
  return (
    <div>
      <p className="mb-4 text-sm text-gray-500">Students › BSCS 3A</p>
      {children}
    </div>
  );
}

Now the student list. The data lives in its own module, so every page can import it:

// lib/students.ts
export type Student = { id: number; name: string; course: string; year: number };

export const students: Student[] = [
  { id: 1, name: "Ana Reyes", course: "BSCS", year: 3 },
  { id: 2, name: "Ben Cruz", course: "BSIT", year: 2 },
  { id: 3, name: "Cara Santos", course: "BSCS", year: 3 },
];

export function findStudent(id: number) {
  return students.find((s) => s.id === id);
}
// app/students/page.tsx
import Link from "next/link";
import { students } from "@/lib/students";

export default function StudentsPage() {
  return (
    <>
      <h1 className="text-2xl font-bold">Students</h1>
      <ul className="mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
        {students.map((s) => (
          <li key={s.id}>
            <Link
              href={`/students/${s.id}`}
              className="block rounded-lg bg-white p-4 shadow hover:shadow-md"
            >
              <span className="font-semibold">{s.name}</span>
              <span className="block text-sm text-gray-500">{s.course} {s.year}</span>
            </Link>
          </li>
        ))}
      </ul>
    </>
  );
}

@/lib/students uses the import alias: @/ means "the project root", so you never write ../../lib/students.

So at /students, the page is wrapped by StudentsLayout, which is wrapped by RootLayout:

RootLayout (html, body, nav)
└── StudentsLayout (breadcrumb)
    └── StudentsPage (the list)

Dynamic routes and route parameters

You can't make a folder for every student. A folder name in square brackets is a dynamic segment: app/students/[id]/page.tsx matches /students/1, /students/2, and any other value. The page receives the value in params.

In current Next.js, params is a Promise, so the page is an async function and awaits it:

// app/students/[id]/page.tsx
import { notFound } from "next/navigation";
import { findStudent } from "@/lib/students";
import LikeButton from "@/app/components/LikeButton";

export default async function StudentPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const student = findStudent(Number(id));

  if (!student) {
    notFound();
  }

  return (
    <article className="rounded-lg bg-white p-6 shadow">
      <h1 className="text-2xl font-bold">{student.name}</h1>
      <p className="text-gray-600">{student.course}, year {student.year}</p>
      <LikeButton />
    </article>
  );
}
  • URL values are always strings, so Number(id) converts "2" to 2.
  • notFound() shows Next.js's "not found" page when the ID doesn't exist, such as /students/99.
  • The name in brackets becomes the property name: [slug] gives params.slug.

With the recommended defaults (Cache Components on), a page that reads params also needs a loading state next to it. Without one, npm run build stops with an error that params was "accessed outside of <Suspense>". Add a loading.tsx file in the same folder; Next.js shows it while the page is prepared:

// app/students/[id]/loading.tsx
export default function Loading() {
  return <p className="text-gray-500">Loading student...</p>;
}

Quick check

Which file shows the page at the URL /subjects/cs324?

Server components and client components

By default, components in the app folder are server components: they run on the server, can read files and databases directly, and send finished HTML to the browser. That's why StudentPage can be async. But server components can't use state or event handlers, because those only exist in the browser.

A component that needs useState, onClick, or useEffect must start with the "use client" directive:

// app/components/LikeButton.tsx
"use client";

import { useState } from "react";

export default function LikeButton() {
  const [liked, setLiked] = useState(false);

  return (
    <button
      onClick={() => setLiked(!liked)}
      className="mt-4 rounded-lg bg-violet-600 px-4 py-2 text-white hover:bg-violet-700"
    >
      {liked ? "❤️ Liked" : "🤍 Like"}
    </button>
  );
}

The usual pattern: pages and layouts stay server components, and only the small interactive pieces (buttons, forms, menus) are client components, used inside them, as StudentPage uses LikeButton. If you see an error like "useState only works in Client Components", add "use client" to the top of that file.

Quick check

A component in the app folder uses useState and onClick. What does it need?

Tailwind CSS

Tailwind CSS is a set of small, single-purpose utility classes that you combine right in your markup, instead of writing a separate stylesheet:

<button class="rounded-lg bg-violet-600 px-4 py-2 font-semibold text-white hover:bg-violet-700">
  Enroll
</button>

Each class does one thing. You'll recognize the CSS from lesson 3:

ClassCSS
p-4, px-4, py-2, mt-2padding / margin (the number × 0.25rem: p-4 = 1rem)
text-sm, text-2xl, font-boldfont size and weight
text-gray-600, bg-white, bg-violet-600colors (shades from 50, lightest, to 950)
rounded-lg, border, shadowcorners, border, shadow
flex, gap-4, items-center, justify-betweenflexbox
grid, grid-cols-3grid
w-full, max-w-4xl, mx-autowidth and centering
hover:bg-violet-700, focus:ring-2styles for a state, using a variant prefix

Tailwind only puts the classes you actually use into the final CSS, so the stylesheet stays small.

Tailwind in a Next.js project

With the recommended defaults, create-next-app already set Tailwind up. To add it to an existing Next.js project:

npm install tailwindcss @tailwindcss/postcss postcss
// postcss.config.mjs
const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

export default config;
/* app/globals.css */
@import "tailwindcss";

Tailwind version 4 needs no other config file. In React, remember to write className, not class.

Try it

The previews on this page load Tailwind's browser build from a CDN, so you can use its classes in plain HTML (a real project uses the setup above instead):

Try it · HTML & CSS

Preview (index.html, updates as you type)

Change bg-violet-600 to bg-sky-600, or rounded-lg to rounded-none, and watch it update.

Responsive breakpoints

Tailwind is mobile first: a class with no prefix applies to every screen size, and a breakpoint prefix applies from that width and up:

PrefixApplies from
(none)0px: phones and up
sm:640px
md:768px
lg:1024px
xl:1280px
2xl:1536px

So grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 means one column on phones, two from 640px, three from 1024px. Design the phone layout first, then add prefixes for bigger screens.

The breakpoints follow the width of the preview, not your whole screen. On a laptop this preview is about 700px wide, so sm: is on; drag your browser window narrower (or open this page on a phone) to see the cards stack:

Try it · HTML & CSS

Preview (index.html, updates as you type)

Quick check

What does class="text-sm md:text-lg" do?

Exercise · HTML & CSS

Responsive subject cards

Style the three cards with Tailwind: put them in a grid with a gap that shows one column on phones and three columns from the `sm:` breakpoint, and give each card padding, rounded corners, a white background, and a shadow.

Preview (index.html, updates as you type)
Hint

Give the wrapper class="grid grid-cols-1 gap-4 sm:grid-cols-3" and each card class="rounded-lg bg-white p-4 shadow".

Show a solution

Try it yourself first — you learn more from a wrong attempt than from reading an answer.

<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

<div class="bg-gray-50 p-4">
  <div class="grid grid-cols-1 gap-4 sm:grid-cols-3">
    <div class="rounded-lg bg-white p-4 shadow">CS 324 Web Development</div>
    <div class="rounded-lg bg-white p-4 shadow">CS 122 Object-Oriented Programming</div>
    <div class="rounded-lg bg-white p-4 shadow">CS 311 Data Structures</div>
  </div>
</div>

Watermelon UI and design consistency

Building every button, card, and menu yourself takes time, and it's hard to make them all match. A component library gives you finished, tested components. This course uses Watermelon UI, an open-source (MIT-licensed) collection of React components, blocks, and templates built with Tailwind CSS and Motion (an animation library).

Watermelon UI isn't one package you import. Like the popular shadcn/ui, it's a registry: a command copies the component's source code into your project, where it becomes your own file that you can read and edit. The command is the shadcn CLI.

1. Set up the shadcn CLI once in your Next.js project. This creates components.json (which tells the CLI where your components go), adds a small cn helper, and sets up CSS variables:

npx shadcn@latest init

2. Add a component by giving the CLI its registry address. For example, Watermelon's split accordion card:

npx shadcn@latest add https://registry.watermelon.sh/r/card-split-accordian.json

(The name is spelled accordian in the registry, so type it exactly.) This writes components/watermelon/card-split-accordian.tsx and installs the packages it needs: motion, lucide-react, react-icons, and react-use-measure.

3. Use it like any of your components: import it from @/components/watermelon/... into a page. Open the file first to see what it exports and which props it takes. It starts with "use client" because it's interactive.

Browse the components at ui.watermelon.sh to choose others. Because the code lands in your project, you can change colors, spacing, and text to match your design, and nothing breaks when the library updates.

Keeping a design consistent

A professional-looking app usually isn't fancy; it's consistent. A few rules get you most of the way:

  • Pick a small palette: one brand color, one neutral (gray), and green/amber/red for status. Use the same shades everywhere.
  • Use the spacing scale, not random values: stick to steps like 2, 4, 6, 8.
  • Same radius and shadow for all cards and buttons (for example rounded-lg shadow).
  • One or two font sizes per level: page titles one size, card titles another, body text another.
  • Reuse components. If two pages need a card, make a Card component (lesson 12) instead of copying classes. Mixing several component libraries makes pages look stitched together.

Tailwind lets you name your brand colors once in globals.css with @theme, so the whole team uses the same values:

/* app/globals.css */
@import "tailwindcss";

@theme {
  --color-brand: #6d28d9;
  --color-brand-dark: #5b21b6;
}

Now bg-brand, text-brand, and hover:bg-brand-dark work like built-in colors, and changing the brand later means editing one line.

Collaborating on GitHub with pull requests

In lesson 10 you used branches and merges on your own computer. On a team, you don't merge your own branch straight into main. You open a pull request (PR): a request, on GitHub, to merge your branch, where teammates can review the changes first.

The everyday flow:

# 1. Start from the latest main
git switch main
git pull

# 2. Make a branch for one feature
git switch -c feature/student-page

# 3. Work and commit as usual
git add .
git commit -m "Add student detail page"

# 4. Push the branch to GitHub
git push -u origin feature/student-page

Then on GitHub:

  1. Open the pull request. GitHub shows a Compare & pull request button for the branch you just pushed. Give it a clear title and describe what you changed and how to test it.
  2. Review. Teammates read the changes in the Files changed tab, leave comments on specific lines, and approve or request changes.
  3. Update. Fix what reviewers asked for, commit, and git push again. The pull request updates by itself.
  4. Merge. When it's approved, click Merge pull request, then delete the branch.
  5. Sync. Everyone runs git switch main and git pull to get the merged work.

Good habits that make reviews easy:

  • One feature per pull request, small enough to review in a few minutes.
  • Never commit .env files or secrets (lesson 17 explains why).
  • Pull main often so your branch doesn't drift far from your teammates' work.
  • Review kindly and specifically: "This breaks on phones because the grid has no grid-cols-1" helps more than "looks wrong".

Common mistakes

  • A page file not named page.tsx: app/about/about.tsx doesn't create a route.
  • Using <a href> for your own pages instead of Link, causing full page reloads.
  • Reading params.id without await. params is a Promise; const { id } = await params.
  • Forgetting "use client" on a component with state or events.
  • Writing class instead of className in .tsx files, so Tailwind classes seem to do nothing.
  • Desktop-first Tailwind: writing grid-cols-3 and then trying to undo it for phones. Start with the phone layout.
  • Mistyping a registry address in shadcn add; copy it exactly.

Summary

  • npx create-next-app@latest creates a Next.js project with TypeScript and Tailwind; npm run dev starts it.
  • In the App Router, folders are routes, page.tsx is a page, and layout.tsx wraps the pages below it. The root layout must contain <html> and <body>.
  • Link navigates between pages. [id] folders are dynamic routes; read the value with const { id } = await params, and add a loading.tsx beside the page.
  • Components are server components by default; add "use client" for state and events.
  • Tailwind styles with utility classes, mobile first, with sm:, md:, lg: prefixes for larger screens; @theme defines brand colors.
  • Watermelon UI components are copied into your project with npx shadcn@latest add <registry URL>; consistent colors, spacing, and reused components keep a design professional.
  • Teams merge work through pull requests: branch, push, open a PR, review, update, merge, pull.

Next: APIs and application data, where your Next.js pages load real data and handle loading, error, and empty states.

References and further reading