Menu

SEO in the Next.js App Router: Metadata, sitemap.ts, robots.ts and JSON-LD
📰

SEO in the Next.js App Router: Metadata, sitemap.ts, robots.ts and JSON-LD

DEV Community: nextjs·Muhammad Hassaan Anjum·6 days ago
#M2h1A4Cm
#devtonextjs#devto#dev#title#input
Long article (1310 words) — no AI summary yet.
Reading 0:00
15s threshold

The App Router has good SEO tools built in, but they are spread over several files and it is easy to get one of them slightly wrong. This is the setup I use on the EventsIQ public site, which has a few hundred pages: features, integrations, docs, a glossary and a blog.

There are four pieces:

Metadata for each page: title, description, canonical URL and share card.

sitemap.ts : every page you want found.

robots.ts : what crawlers may fetch.

JSON-LD : structured data that tells Google what a page is.

1. One helper for every page's metadata

Each page exports metadata or generateMetadata . Rather than repeat the same fields everywhere, I use one helper:

import type { Metadata } from "next" ;

export function pageMetadata ( input : { title : string ; description : string ; path : string ; type ?: "website" | "article" ; publishedTime ?: string ; } ) : Metadata { const image = `/api/og?${new URLSearchParams({ title: input.title })}` ; return { title : input . title , description : input .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.