PTH Software logo
  • SEO
  • Next.js
  • Hướng dẫn

Next.js SEO: A Complete Guide for the App Router

A practical guide to Next.js SEO with the App Router: metadata, sitemap, robots.txt, structured data, multilingual sites and page speed.

3 min read

Next.js SEO: A Complete Guide for the App Router

Next.js is one of the most search-engine-friendly frameworks available, but good Next.js SEO doesn't come for free just because you picked the right framework. This guide covers what you need to do so that a Next.js site built with the App Router is understood correctly by Google, indexed quickly and presented well in search results.

Why Next.js SEO needs deliberate work

Next.js renders HTML on the server, so crawlers receive the full content on the very first request. That is a big advantage over apps that only render in the browser. Page titles, descriptions, canonical URLs, sitemaps and structured data, however, are still yours to declare. Without them Google can still read the page, but it has to guess, and the result is rarely what you want.

Declaring metadata with generateMetadata

With the App Router, every page can export a generateMetadata function that returns its title, description, canonical URL and Open Graph data. Next.js generates the matching <title> and <meta> tags for you, no extra library required.

export async function generateMetadata({ params }): Promise<Metadata> {
  const post = await getPost((await params).slug);
  return {
    title: post.title,
    description: post.summary,
    alternates: { canonical: `https://example.com/blog/${post.slug}` },
    openGraph: { type: "article", images: [post.coverImage] },
  };
}

A few things to keep in mind:

  • Every page should have its own title, around 50–60 characters, containing the main keyword.
  • Keep descriptions around 120–160 characters, and write them to earn the click, not to stuff keywords.
  • If a page sets its own openGraph, repeat shared fields such as siteName: layout metadata is only merged one level deep.

Built-in sitemap and robots.txt

Instead of reaching for a third-party package, create app/sitemap.ts and app/robots.ts. The sitemap should list every public page, with its last-modified date and its other language versions. Use robots.txt to block areas that don't need indexing, such as the admin panel, and to point crawlers to the sitemap.

If your content comes from a database, render the sitemap on each request so new posts appear immediately without a rebuild.

Structured data (JSON-LD)

Structured data tells Google whether a page is an article, a product or a list of FAQs. For a blog, use BlogPosting together with BreadcrumbList. In Next.js you simply render a <script type="application/ld+json"> tag inside the page component. Remember to escape the < character when serializing to JSON, to avoid XSS.

You can validate the result with Google's Rich Results Test.

Multilingual sites and hreflang

If your site has several languages, give each one its own URL, for example /blog/... and /en/blog/.... Let the URL decide the language instead of redirecting based on the browser or a cookie. Then declare alternates.languages to generate hreflang tags, with x-default pointing to the main language. Pages that have no translation yet should use the original as their canonical, so they aren't treated as duplicate content.

Page speed and Core Web Vitals

Speed is a ranking signal, and it directly affects whether readers stay. Some things worth doing:

  1. Use next/image so images are compressed, sized for the screen and lazy loaded.
  2. Mark the largest image at the top of the page (usually the cover) to load early, improving LCP.
  3. Use next/font so fonts load without layout shifts, improving CLS.
  4. Keep most components on the server and only use client components where interaction is really needed.

Next.js SEO checklist before publishing

  • ✅ A unique title and description for every page
  • ✅ A correct canonical URL that doesn't point to another page
  • ✅ The page is in the sitemap and not blocked by robots.txt
  • ✅ Exactly one H1, with sections in H2/H3
  • ✅ Images have alt text describing their content
  • ✅ JSON-LD passes the Rich Results Test
  • ✅ The sitemap is submitted in Google Search Console

Conclusion

Next.js already ships almost every tool you need for SEO. What's left is applying them consistently on every page. If you want a Next.js website that is SEO-ready from day one, get in touch with us for a consultation.

View all posts
View all posts

Your project could be next

Tell us about your idea and we will propose the right solution.

Get in touch