Metadata and SEO — Complete Guide
Metadata and SEO — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Next.js Tutorial on Toolliyo Academy.
On this page
Next.js Tutorial (LearnHub) · Lesson 26 of 100
Metadata and SEO
Beginner ✓ → Intermediate → Advanced → Professional
Intermediate · 2 — Building apps · ~14 min read · Module 3: Data & Forms
Introduction
You know the basics now. Here we use Metadata and SEO in real LearnHub screens — layouts, data, and APIs. Still plain language, just a bit more depth. Metadata sets
Data and forms power course lists, enrollments, and progress. Learn these patterns slowly — test in a small page first.
When will you use this?
Reach for data fetching and Server Actions when pages need database content or form submissions.
- Enrollments, quiz scores, and course progress load from the server — often with Server Actions.
- Forms that enroll a student in a course use Server Actions instead of a separate REST call.
Real-world: Swiggy-style delivery tracker
The Food tech team building Swiggy-style delivery tracker uses Metadata and SEO to rank course landing pages on Google with proper titles and descriptions. customers and riders never see the TypeScript files — they just get a fast, reliable live order map and status updates.
Production-style code
// app/courses/[slug]/page.tsx
import type { Metadata } from 'next';
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
return {
title: `${slug} — LearnHub`,
description: 'Enroll and start learning today.'
};
}
What happens in production: In Swiggy-style delivery tracker, getting Metadata and SEO right means customers and riders trust the live order map and status updates every day.
Lesson example (start here)
Copy this smaller example first. Once it works, compare it with the real-world code above.
import type { Metadata } from 'next';
export const metadata: Metadata = {
title: 'LearnHub — Online courses that stick',
description: 'Build skills with structured Next.js and frontend courses.',
openGraph: {
title: 'LearnHub',
description: 'Toolliyo-style learning platform',
type: 'website'
}
};
// Dynamic — app/courses/[slug]/page.tsx
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
return {
title: `${slug.replace(/-/g, ' ')} | LearnHub`,
description: `Enroll in ${slug} and track your progress.`
};
}
Line-by-line walkthrough
| Code | What it means |
|---|---|
import type { Metadata } from 'next'; | Imports a module so you can use its exports in this file. |
export const metadata: Metadata = { | Page metadata — title and description for SEO and social sharing. |
title: 'LearnHub — Online courses that stick', | Part of the Metadata and SEO example — read it together with the lines before and after. |
description: 'Build skills with structured Next.js and frontend courses.', | Part of the Metadata and SEO example — read it together with the lines before and after. |
openGraph: { | Part of the Metadata and SEO example — read it together with the lines before and after. |
title: 'LearnHub', | Part of the Metadata and SEO example — read it together with the lines before and after. |
description: 'Toolliyo-style learning platform', | Part of the Metadata and SEO example — read it together with the lines before and after. |
type: 'website' | Part of the Metadata and SEO example — read it together with the lines before and after. |
} | Closes a block started by { above. |
}; | Closes a block started by { above. |
// Dynamic — app/courses/[slug]/page.tsx | Comment — notes for humans; the compiler ignores it. |
export async function generateMetadata({ params }: Props): Promise<Metadata> { | Exported async function — often a Server Action or API handler. |
const { slug } = await params; | Part of the Metadata and SEO example — read it together with the lines before and after. |
return { | Part of the Metadata and SEO example — read it together with the lines before and after. |
How it works (big picture)
- Static metadata on marketing pages.
- generateMetadata fetches course title for dynamic SEO.
- Open Graph improves link previews on WhatsApp and LinkedIn.
Do this on your computer
- Set metadata on root layout or home page
- Add generateMetadata to course detail page
- View page source — confirm title tag
- Share URL in social debugger tool
- Read the real-world section and name which part of LearnHub uses this topic.
- Run the example locally with npm run dev and confirm the same behavior.
- Change one value in the example (route, text, or course id) and predict what will happen before you save.
Experiments — try changing this
- Change a string or route in the example and save — watch the browser update.
- Break the code on purpose (remove a bracket), read the error overlay, then fix it.
- Change the API URL or course id and see how the page data changes.
- Use npm run dev while editing Metadata and SEO — the page hot-reloads on save.
Remember
metadata export for static SEO. generateMetadata for dynamic routes. Open Graph for social previews.
Common questions
sitemap.xml?
Covered in advanced SEO lessons — use app/sitemap.ts in App Router.
How long should I spend on Metadata and SEO?
Until you can explain it in your own words and run the example without looking at the answer. Beginners often need 30–60 minutes per new concept; setup lessons may take one afternoon.
What if I get stuck on Metadata and SEO?
Re-read the line-by-line walkthrough, check the terminal and browser overlay for errors, and compare your code character-by-character with the example. Search the exact error text — someone else had it too.
Where is Metadata and SEO used in real jobs?
See the real-world section above — the same pattern appears in LMS, e-commerce, SaaS, and dashboards. Interviewers ask you to explain it using one concrete example.