# Hide Next.js Pages with Metadata Robots

> Prevent search engines from indexing specific Next.js pages using metadata robots

This technique uses Next.js App Router metadata configuration to prevent search engine indexing on a per-page basis. Exporting a robots object with index set to false injects a noindex meta tag into the document head. Crucially, the page must not be blocked in robots.txt so crawlers can access the page to read the directive.

## How it works

1. In your Next.js page file, import \`Metadata\` from \`'next'\` and export a \`metadata\` object:

\`\`\`typescript

import { Metadata } from "next";

export const metadata: Metadata = {

title: "Privacy Policy",

robots: {

index: false,

follow: true,

},

};

\`\`\`

2. Next.js will inject \`\<meta name="robots" content="noindex, follow"\>\` into the \`\<head\>\` of the page.

3. Crucial Rule: Do NOT block the URL in your \`robots.txt\` file (or \`robots()\` route handler). If blocked in \`robots.txt\`, search engine crawlers cannot crawl the page to read the \`noindex\` tag, and the URL could still appear in Google search results if other pages link to it.

## What it is for

- Prevent staging, admin, or internal utility pages from appearing in Google search results
- Keep legal, thank-you, or confirmation pages out of public index lists
- Allow search crawlers to follow outbound links on unindexed pages

## Key points

- Import Metadata type from 'next' in your Next.js App Router page
- Define and export a metadata object specifying robots settings
- Set robots: { index: false, follow: true } to block indexing while preserving link equity
- Next.js automatically renders \<meta name="robots" content="noindex, follow"\> in the head
- Avoid disallowing the path in robots.txt so crawlers can read the noindex directive

## Pricing

Free

## Details

- Type: Tip
- Category: [Development](https://xiry.app/topics/development.md)
- Open source: yes
- Platforms: Web, Code library
- For: Next.js developers managing SEO and page visibility
- Tags: nextjs, react, seo, webdev, app router

## Why it was saved

- [@codinginflow, 17 January 2024](https://www.instagram.com/reel/C2M2XfjN6OB/): Properly keeps private or utility pages (e.g., privacy policies, admin dashboards) out of Google search results without risking search engine leaks.

## Related

- [How loading.jsx Works with Suspense in Next.js](https://xiry.app/resources/how-loading-jsx-works-with-suspense-in-next-js): Route-level loading.jsx vs granular React Suspense boundaries in Next.js App Router. (Tip, Free)
- [shadcn/ui](https://xiry.app/resources/shadcn-ui-1902): Copy-paste React UI components built with Tailwind CSS and Radix primitives. (Website, Open source)
- [Efferd](https://xiry.app/resources/efferd): Pre-built, responsive shadcn/ui blocks and layouts for React applications (Web app, Freemium)
- [Spell UI](https://xiry.app/resources/spell-ui): Refined, copy-paste React and Tailwind CSS components with micro-interactions (GitHub repo, Open source)
- [Above-the-Fold Deferred Rendering Pattern](https://xiry.app/resources/above-the-fold-deferred-rendering-pattern): Performance pattern for deferring below-the-fold components to accelerate perceived page load. (Tip, Free)
- [Cult UI](https://xiry.app/resources/cult-ui-2540): Open-source animated UI components and blocks built for shadcn/ui projects (Website, Free)

Updated 3 October 2026. Page: https://xiry.app/resources/hide-next-js-pages-with-metadata-robots

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
