Fix indexing issues in Next.js by generating a dynamic sitemap.xml using the App Router sitemap.js convention, configuring robots.txt to allow crawling, submitting the sitemap in Google Search Console, and ensuring every page has proper metadata with canonical URLs. This resolves most "discovered but not indexed" errors.
Fix indexing issues in Next.js by generating a dynamic sitemap.xml using the App Router sitemap.js convention, configuring robots.txt to allow crawling, submitting the sitemap in Google Search Console, and ensuring every page has proper metadata with canonical URLs. This resolves most "discovered but not indexed" errors.
The "Discovered - currently not indexed" Problem
- •Google knows your page exists but hasn't crawled it yet.
- •Causes: Poor internal linking, duplicate content, or sitemap issues.
- •Fix: Submit a clean, valid sitemap and improve content quality.
You built a blazing fast Next.js portfolio. You deployed it. But when you check Google Search Console, you see the dreaded status: "Discovered - currently not indexed". Why? And how did I fix it for my own site?
Why Do Static Sitemaps Cause Indexing Problems in Next.js?
Many Next.js developers (myself included) start with a manually created `sitemap.xml`. This works for small sites, but as you add blog posts, manually updating the XML file becomes a chore. If your sitemap `lastmod` date doesn't match the actual content update, Google might ignore it.
The Solution: Next.js Metadata Route API
Instead of a static file, use `app/sitemap.js` (or `.ts`) to generate it programmatically.
import { blogData } from '../assets/assets';
export default function sitemap() {
const baseUrl = 'https://aditya-gupta.com.np';
// Blog posts dynamic generation
const blogPosts = blogData.map((blog) => ({
url: `${baseUrl}/blogs/${blog.id}`,
lastModified: new Date(blog.date),
changeFrequency: 'weekly',
priority: 0.7,
}));
return [
{
url: baseUrl,
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
...blogPosts,
];
}How Do You Set Up robots.txt Correctly in Next.js?
Your robot needs a map. The `robots.txt` file tells search crawlers where to find your sitemap. Without it, they are wandering blind.
export default function robots() {
return {
rules: {
userAgent: '*',
allow: '/',
disallow: '/private/',
},
sitemap: 'https://aditya-gupta.com.np/sitemap.xml',
}
}How Do You Optimize Metadata Using the Next.js App Router?
Having a page isn't enough; it needs to look good when shared. I migrated from the old `Head` component to the new Metadata API in Next.js 14+.
❌ The Old Way (Page Router)
<Head>
<title>My Page</title>
</Head>
✅ The New Way (App Router)
export const metadata = {
title: 'My Page',
description: '...'
}
What Results Did These SEO Changes Achieve?
After deploying these changes, I resubmitted my sitemap to Google Search Console. Within 48 hours, my "Discovered - currently not indexed" pages were moved to "Indexed", and my organic impressions started to climb.
Frequently Asked Questions
Need Help with Next.js SEO?
Technical SEO can be tricky. I can audit your Next.js site.

