<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>next.js guide | ServerAvatar</title>
	<atom:link href="https://serveravatar.com/tag/next-js-guide/feed/" rel="self" type="application/rss+xml" />
	<link>https://serveravatar.com</link>
	<description>The first, Fully Hybrid Cloud Hosting Solution.</description>
	<lastBuildDate>Wed, 24 Sep 2025 10:13:53 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://serveravatar.com/wp-content/uploads/2025/02/cropped-favicon-32x32.png</url>
	<title>next.js guide | ServerAvatar</title>
	<link>https://serveravatar.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Generate a Next.js Sitemap Easily to Boost SEO Rank</title>
		<link>https://serveravatar.com/generate-next-js-sitemap-boost-seo-ranking/</link>
		
		<dc:creator><![CDATA[Suresh Ramani]]></dc:creator>
		<pubDate>Mon, 21 Jul 2025 18:35:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[boost seo]]></category>
		<category><![CDATA[next.js guide]]></category>
		<category><![CDATA[next.js seo]]></category>
		<category><![CDATA[next.js sitemap]]></category>
		<category><![CDATA[next.js tutorial]]></category>
		<category><![CDATA[search engine optimization]]></category>
		<category><![CDATA[seo optimization]]></category>
		<guid isPermaLink="false">https://serveravatar.com/?p=26427</guid>

					<description><![CDATA[<p>Introduction to Sitemaps Imagine your website is a house, and a sitemap is the blueprint. It tells search engines exactly where to go, what each room (page) is for, and how everything is connected. Simple, right? A sitemap is essentially a list of all the important URLs on your website. It helps search engines crawl [&#8230;]</p>
<p>The post <a href="https://serveravatar.com/generate-next-js-sitemap-boost-seo-ranking/">Generate a Next.js Sitemap Easily to Boost SEO Rank</a> first appeared on <a href="https://serveravatar.com">ServerAvatar</a>.</p>]]></description>
										<content:encoded><![CDATA[<figure class="wp-block-image size-large"><a href="https://serveravatar.com?ref=blog" target="_blank" rel=" noreferrer noopener"><img fetchpriority="high" decoding="async" width="1024" height="127" src="https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-1024x127.png" alt="Blog banner - ServerAvatar" class="wp-image-28182" srcset="https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-1024x127.png 1024w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-300x37.png 300w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-768x95.png 768w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-1536x190.png 1536w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-3-2048x253.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<h2 class="wp-block-heading">Introduction to Sitemaps</h2>



<p>Imagine your website is a house, and a sitemap is the blueprint. It tells search engines exactly where to go, what each room (page) is for, and how everything is connected. Simple, right?</p>



<p>A sitemap is essentially a <strong>list of all the important URLs</strong> on your website. It helps search engines crawl your site more efficiently, which means better visibility in search results.</p>



<h2 class="wp-block-heading">Why Your Next.js Website Needs a Sitemap</h2>



<p>Let’s be honest &#8211; if Google can&#8217;t find your pages, neither can your customers. Without a sitemap, your amazing blog posts, product pages, or service descriptions could be floating around in internet limbo.</p>



<p><strong>Benefits of a sitemap in Next.js:</strong></p>



<ul class="wp-block-list">
<li>Better search engine indexing</li>



<li>Easier discovery of dynamic pages</li>



<li>Improved SEO performance</li>
</ul>



<p>If you want to <strong>boost your Next.js site&#8217;s SEO</strong>, a sitemap is not optional &#8211; it&#8217;s essential.</p>



<h2 class="wp-block-heading">Understanding the Sitemap Structure</h2>



<p>A standard sitemap is just an <strong>XML file</strong>. Yes, the same format used since the dawn of the internet. Here&#8217;s a simple version:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">XML</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  &lt;url>
    &lt;loc>https://example.com/&lt;/loc>
    &lt;lastmod>2025-07-21&lt;/lastmod>
    &lt;changefreq>daily&lt;/changefreq>
    &lt;priority>1.0&lt;/priority>
  &lt;/url>
&lt;/urlset></textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #808080">&lt;</span><span style="color: #569CD6">urlset</span><span style="color: #D4D4D4"> </span><span style="color: #9CDCFE">xmlns</span><span style="color: #D4D4D4">=</span><span style="color: #CE9178">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">url</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">loc</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">https://example.com/</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">loc</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">lastmod</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">2025-07-21</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">lastmod</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">changefreq</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">daily</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">changefreq</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #808080">&lt;</span><span style="color: #569CD6">priority</span><span style="color: #808080">&gt;</span><span style="color: #D4D4D4">1.0</span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">priority</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #808080">&lt;/</span><span style="color: #569CD6">url</span><span style="color: #808080">&gt;</span></span>
<span class="line"><span style="color: #808080">&lt;/</span><span style="color: #569CD6">urlset</span><span style="color: #808080">&gt;</span></span></code></pre></div>



<p>Each <code>&lt;url&gt;</code> tag contains:</p>



<ul class="wp-block-list">
<li><strong>loc</strong>: the actual URL</li>



<li><strong>lastmod</strong>: last modification date</li>



<li><strong>changefreq</strong>: how often the page changes</li>



<li><strong>priority</strong>: importance of the page (0.0 to 1.0)</li>
</ul>



<h2 class="wp-block-heading">Static vs Dynamic Sitemaps</h2>



<p>Let&#8217;s break this down:</p>



<ul class="wp-block-list">
<li><strong>Static Sitemap</strong>: Fixed pages like About, Contact, etc.</li>



<li><strong>Dynamic Sitemap</strong>: Pages generated from content (e.g., blog posts, product listings)</li>
</ul>



<p>If you&#8217;re using <strong>Next.js&#8217;s dynamic routing</strong>, you’ll likely need a <strong>dynamic sitemap</strong>.</p>



<h2 class="wp-block-heading">Choosing the Right Method in Next.js</h2>



<p>You have <strong>two main options</strong> to create a sitemap in Next.js:</p>



<ul class="wp-block-list">
<li><strong>Using a ready-made package (like next-sitemap)</strong></li>



<li><strong>Creating your own custom sitemap</strong></li>
</ul>



<p>If you&#8217;re just starting, the <strong>first option is much easier</strong>. But for full control, the manual method is also worth exploring.</p>



<h2 class="wp-block-heading">Using a Package: Next-Sitemap</h2>



<p>The easiest and most popular way is by using the <a href="https://www.npmjs.com/package/next-sitemap" title="">next-sitemap</a> package. It&#8217;s like hiring a tour guide for Google &#8211; showing it around your site without you doing all the talking.</p>



<h3 class="wp-block-heading"><strong>Why use next-sitemap?</strong></h3>



<ul class="wp-block-list">
<li>Simple configuration</li>



<li>Supports dynamic and static routes</li>



<li>Auto-generates <code>robots.txt</code></li>
</ul>



<p>To install:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">Bash</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>npm install next-sitemap</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #DCDCAA">npm</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">install</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">next-sitemap</span></span></code></pre></div>



<p>Or if you&#8217;re using Yarn:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">Bash</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>yarn add next-sitemap</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #DCDCAA">yarn</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">add</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">next-sitemap</span></span></code></pre></div>



<h2 class="wp-block-heading">Step-by-Step Setup with Next-Sitemap</h2>



<p>Here&#8217;s how to get it up and running:</p>



<ul class="wp-block-list">
<li><strong>Create a <code>next-sitemap.config.js</code></strong> in your project root:</li>
</ul>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">JavaScript</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>/** @type {import('next-sitemap').IConfig} */
module.exports = {
  siteUrl: 'https://yourdomain.com',
  generateRobotsTxt: true,
  changefreq: 'daily',
  priority: 0.7,
  sitemapSize: 5000,
};</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #6A9955">/** </span><span style="color: #569CD6">@type</span><span style="color: #6A9955"> </span><span style="color: #4EC9B0">{import(&#39;next-sitemap&#39;).IConfig}</span><span style="color: #6A9955"> */</span></span>
<span class="line"><span style="color: #4EC9B0">module</span><span style="color: #D4D4D4">.</span><span style="color: #4EC9B0">exports</span><span style="color: #D4D4D4"> = {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">siteUrl:</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">&#39;https://yourdomain.com&#39;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">generateRobotsTxt:</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">true</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">changefreq:</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">&#39;daily&#39;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">priority:</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">0.7</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">sitemapSize:</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">5000</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">};</span></span></code></pre></div>



<ul class="wp-block-list">
<li><strong>Update <code>package.json</code></strong> with a build script:</li>
</ul>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">JSON</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>"scripts": {
  "postbuild": "next-sitemap"
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #CE9178">&quot;scripts&quot;</span><span style="color: #D4D4D4">: {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">&quot;postbuild&quot;</span><span style="color: #D4D4D4">: </span><span style="color: #CE9178">&quot;next-sitemap&quot;</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<ul class="wp-block-list">
<li><strong>Build your project</strong>:</li>
</ul>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">Bash</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>npm run build</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #DCDCAA">npm</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">run</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">build</span></span></code></pre></div>



<p>That&#8217;s it! Your sitemap is now generated under the <code>public/</code> folder.</p>



<h2 class="wp-block-heading">Creating a Custom Sitemap Manually</h2>



<p>Feeling adventurous? Here’s how to build your own:</p>



<ol class="wp-block-list">
<li>Create a new API route at <code>pages/api/sitemap.js</code>.</li>



<li>Fetch all your dynamic routes (e.g., blog posts).</li>



<li>Generate XML content.</li>



<li>Set headers and return the XML response.</li>
</ol>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">JavaScript</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>export default async function handler(req, res) {
  const baseUrl = 'https://yourdomain.com';
  const paths = &#91;'/', '/about', '/contact'&#93;;

  const sitemap = `&lt;?xml version="1.0" encoding="UTF-8"?>
  &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    ${paths
      .map(path => `&lt;url>&lt;loc>${baseUrl}${path}&lt;/loc>&lt;/url>`)
      .join('')}
  &lt;/urlset>`;

  res.setHeader('Content-Type', 'text/xml');
  res.write(sitemap);
  res.end();
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #C586C0">export</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">default</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">async</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">function</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">handler</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">req</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">res</span><span style="color: #D4D4D4">) {</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">baseUrl</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&#39;https://yourdomain.com&#39;</span><span style="color: #D4D4D4">;</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">paths</span><span style="color: #D4D4D4"> = &#91;</span><span style="color: #CE9178">&#39;/&#39;</span><span style="color: #D4D4D4">, </span><span style="color: #CE9178">&#39;/about&#39;</span><span style="color: #D4D4D4">, </span><span style="color: #CE9178">&#39;/contact&#39;</span><span style="color: #D4D4D4">&#93;;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">sitemap</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">`&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span></span>
<span class="line"><span style="color: #CE9178">  &lt;urlset xmlns=&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;&gt;</span></span>
<span class="line"><span style="color: #CE9178">    </span><span style="color: #569CD6">${</span><span style="color: #9CDCFE">paths</span></span>
<span class="line"><span style="color: #D4D4D4">      .</span><span style="color: #DCDCAA">map</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">path</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">=&gt;</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">`&lt;url&gt;&lt;loc&gt;</span><span style="color: #569CD6">${</span><span style="color: #9CDCFE">baseUrl</span><span style="color: #569CD6">}${</span><span style="color: #9CDCFE">path</span><span style="color: #569CD6">}</span><span style="color: #CE9178">&lt;/loc&gt;&lt;/url&gt;`</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">      .</span><span style="color: #DCDCAA">join</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&#39;&#39;</span><span style="color: #D4D4D4">)</span><span style="color: #569CD6">}</span></span>
<span class="line"><span style="color: #CE9178">  &lt;/urlset&gt;`</span><span style="color: #D4D4D4">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">res</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">setHeader</span><span style="color: #D4D4D4">(</span><span style="color: #CE9178">&#39;Content-Type&#39;</span><span style="color: #D4D4D4">, </span><span style="color: #CE9178">&#39;text/xml&#39;</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">res</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">write</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">sitemap</span><span style="color: #D4D4D4">);</span></span>
<span class="line"><span style="color: #D4D4D4">  </span><span style="color: #9CDCFE">res</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">end</span><span style="color: #D4D4D4">();</span></span>
<span class="line"><span style="color: #D4D4D4">}</span></span></code></pre></div>



<h2 class="wp-block-heading">Adding Dynamic Routes to Your Sitemap</h2>



<p>If your blog or app has <strong>dynamic content</strong>, like user profiles or product pages, fetch these from your database or CMS:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">JavaScript</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>const dynamicRoutes = await fetchPosts(); // Assume this fetches blog slugs
const urls = dynamicRoutes.map(post => `/blog/${post.slug}`);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">dynamicRoutes</span><span style="color: #D4D4D4"> = </span><span style="color: #C586C0">await</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">fetchPosts</span><span style="color: #D4D4D4">(); </span><span style="color: #6A9955">// Assume this fetches blog slugs</span></span>
<span class="line"><span style="color: #569CD6">const</span><span style="color: #D4D4D4"> </span><span style="color: #4FC1FF">urls</span><span style="color: #D4D4D4"> = </span><span style="color: #9CDCFE">dynamicRoutes</span><span style="color: #D4D4D4">.</span><span style="color: #DCDCAA">map</span><span style="color: #D4D4D4">(</span><span style="color: #9CDCFE">post</span><span style="color: #D4D4D4"> </span><span style="color: #569CD6">=&gt;</span><span style="color: #D4D4D4"> </span><span style="color: #CE9178">`/blog/</span><span style="color: #569CD6">${</span><span style="color: #9CDCFE">post</span><span style="color: #D4D4D4">.</span><span style="color: #9CDCFE">slug</span><span style="color: #569CD6">}</span><span style="color: #CE9178">`</span><span style="color: #D4D4D4">);</span></span></code></pre></div>



<p>Include them in your sitemap just like the static ones.</p>



<h2 class="wp-block-heading">Automating Sitemap Generation</h2>



<p>You don&#8217;t want to regenerate your sitemap manually every time you add a new page. Use <code>next-sitemap</code> or a custom build script that runs after deployment.</p>



<p><strong>Tip</strong>: Use GitHub Actions or Vercel’s post-build hook to auto-generate your sitemap on deployment.</p>



<figure class="wp-block-image size-large"><a href="https://serveravatar.com?ref=blog" target="_blank" rel=" noreferrer noopener"><img decoding="async" width="1024" height="127" src="https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-1024x127.png" alt="Blog banner - ServerAvatar" class="wp-image-28184" srcset="https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-1024x127.png 1024w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-300x37.png 300w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-768x95.png 768w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-1536x190.png 1536w, https://serveravatar.com/wp-content/uploads/2025/09/728_90-Banner-1-2048x254.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<h2 class="wp-block-heading">Adding the Sitemap to robots.txt</h2>



<p>If you&#8217;re serious about SEO, your <code>robots.txt</code> should point to your sitemap:</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7">Plaintext</span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>User-agent: *
Allow: /

Sitemap: https://yourdomain.com/sitemap.xml</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">User-agent: *</span></span>
<span class="line"><span style="color: #D4D4D4">Allow: /</span></span>
<span class="line"><span style="color: #D4D4D4"></span></span>
<span class="line"><span style="color: #D4D4D4">Sitemap: https://yourdomain.com/sitemap.xml</span></span></code></pre></div>



<p>If you&#8217;re using <code>next-sitemap</code>, it handles this automatically.</p>



<p>Not sure how to create or edit your <code>robots.txt</code> file? Don’t worry &#8211; we&#8217;ve got you covered. Check out the free and easy-to-use <strong><a class="" href="https://serveravatar.com/robots-txt-generator/">Robots.txt Generator by ServerAvatar</a></strong>. It helps you create a valid file in seconds, even if you&#8217;re not a techie.</p>



<h2 class="wp-block-heading">Submitting Your Sitemap to Google</h2>



<p>Go to <strong>Google Search Console</strong> -&gt; Select your property -&gt; Sitemaps -&gt; Add your sitemap URL (<code>sitemap.xml</code>) -&gt; Submit.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="354" src="https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google-1024x354.webp" alt="Next.js Sitemap" class="wp-image-26432" srcset="https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google-1024x354.webp 1024w, https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google-300x104.webp 300w, https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google-768x266.webp 768w, https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google-1536x532.webp 1536w, https://serveravatar.com/wp-content/uploads/2025/07/submit-sitemap-google.webp 1898w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Boom! Google is now officially invited to crawl your site.</p>



<h2 class="wp-block-heading">Common Mistakes and How to Avoid Them</h2>



<ul class="wp-block-list">
<li>Forgetting to update your sitemap after adding new pages</li>



<li>Incorrect URL formatting</li>



<li>Missing trailing slashes (if your site uses them)</li>



<li>Sitemap too large (split into multiple if over 50,000 URLs)</li>
</ul>



<p>Always test your sitemap using <a>Google’s Sitemap Validator</a>.</p>



<h2 class="wp-block-heading">Tips for Keeping Your Sitemap Updated</h2>



<ul class="wp-block-list">
<li>Use <code>getStaticPaths</code> or <code>getServerSideProps</code> to fetch routes dynamically</li>



<li>Schedule regular rebuilds (weekly or daily)</li>



<li>Use timestamps in your sitemap to indicate updates</li>



<li>Remove deleted pages from your sitemap</li>
</ul>



<p>Think of your sitemap like a daily planner &#8211; keep it updated for best results.</p>



<h2 class="wp-block-heading">Conclusion and Best Practices</h2>



<p>Creating a <strong>nextjs sitemap</strong> doesn&#8217;t have to be complicated. Whether you&#8217;re building a personal blog or an eCommerce store, a sitemap is your direct line to Google and other search engines.</p>



<p><strong>Here&#8217;s a quick recap</strong>:</p>



<ul class="wp-block-list">
<li>Use <strong>next-sitemap</strong> for a hassle-free setup</li>



<li>Build it manually if you need full control</li>



<li>Always include dynamic routes</li>



<li>Submit to search engines and monitor performance</li>



<li>Keep it updated as your site grows</li>
</ul>



<p>Remember, your sitemap is like rolling out a red carpet for search engines. Make it smooth, clean, and welcoming.</p>



<h2 class="wp-block-heading">Frequently Asked Questions</h2>



<div data-schema-only="false" class="wp-block-aioseo-faq"><h3 class="aioseo-faq-block-question">Can I use next-sitemap with dynamic routes in Next.js?</h3><div class="aioseo-faq-block-answer">
<p>Yes! <code>next-sitemap</code> automatically includes dynamic routes if you configure your project correctly and use <code>getStaticPaths</code>.</p>
</div></div>



<div data-schema-only="false" class="wp-block-aioseo-faq"><h3 class="aioseo-faq-block-question">Do I need to submit my sitemap manually to Google?</h3><div class="aioseo-faq-block-answer">
<p>You can, but it&#8217;s also detected through <code>robots.txt</code> if configured properly. Submitting manually gives you quicker feedback.</p>
</div></div>



<div data-schema-only="false" class="wp-block-aioseo-faq"><h3 class="aioseo-faq-block-question">How often should I update my sitemap?</h3><div class="aioseo-faq-block-answer">
<p>Whenever you add or remove significant content &#8211; blogs, products, pages &#8211; it&#8217;s a good idea to regenerate it.</p>
</div></div>



<div data-schema-only="false" class="wp-block-aioseo-faq"><h3 class="aioseo-faq-block-question">Is it okay to have multiple sitemaps?</h3><div class="aioseo-faq-block-answer">
<p>Absolutely. If your site has over 50,000 URLs, you should split them into multiple sitemaps and reference them in a sitemap index.</p>
</div></div>



<div data-schema-only="false" class="wp-block-aioseo-faq"><h3 class="aioseo-faq-block-question">Can I use next-sitemap on a Vercel-hosted Next.js site?</h3><div class="aioseo-faq-block-answer">
<p>Yes, and it works great! Just make sure to set up your build and deployment scripts correctly.</p>
</div></div>



<div style="font-family: 'Public Sans', sans-serif; background: #fff; border: 1px solid #e1eaff; padding: 40px 35px; border-radius: 16px; margin: 60px 0; box-shadow: 0 10px 32px rgba(0, 0, 0, 0.05); max-width: 860px; margin-left: auto; margin-right: auto; text-align: center;">

  <h2 style="font-size: 28px; font-weight: 800; color: #0b2b53; margin-top: 0; margin-bottom: 16px;">
    Stop Wasting Time on Servers. Start Building Instead.
  </h2>

  <p style="font-size: 17px; color: #333; font-weight: 500; margin: 0 0 12px;">
    You didn’t start your project to babysit servers.
    Let <strong>ServerAvatar</strong> handle deployment, monitoring, and backups —
    so you can focus on growth.
  </p>

  <p style="font-size: 16px; color: #555; font-weight: 400; margin-bottom: 26px;">
    Deploy <strong>WordPress, Laravel, N8N</strong>, and more in minutes.
    No DevOps required. No command line. No stress.
  </p>

  <a href="https://app.serveravatar.com" target="_blank" rel="noopener" style="display: inline-block; background: linear-gradient(135deg, #007bff, #0056d2); color: #fff; text-decoration: none; padding: 16px 30px; font-size: 17px; font-weight: 700; border-radius: 10px; transition: background 0.3s ease;">
    🚀 Try ServerAvatar Free – No Credit Card Needed
  </a>

  <p style="font-size: 14px; color: #888; margin-top: 18px;">
    Trusted by 10,000+ developers and growing.
  </p>
</div><p>The post <a href="https://serveravatar.com/generate-next-js-sitemap-boost-seo-ranking/">Generate a Next.js Sitemap Easily to Boost SEO Rank</a> first appeared on <a href="https://serveravatar.com">ServerAvatar</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
