Nuxt SiteMap

I am using the Nuxt SEO Module out of box without much configuration (except for the basic one). I am not able to get the dynamic pages indexed on the sitemap. What am I doing wrong?
8 Replies
kapa.ai
kapa.ai4w ago
Hi @Sagar Kapoor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To address your issue with dynamic pages not being indexed in the sitemap when using the Nuxt SEO Module, there are a few things you can try: 1. Ensure you're using the latest version of the Nuxt SEO Module, which includes sitemap functionality. 2. For dynamic pages, you need to add an API source for the sitemap to generate these pages. You can follow the guide for dynamic URLs in the Nuxt SEO documentation: Dynamic URLs (https://nuxtseo.com/sitemap/guides/dynamic-urls) 3. If you're using Nuxt Content, there's a specific integration guide you can follow: Nuxt Content Integration (https://nuxtseo.com/sitemap/integrations/content) 4. Make sure your dynamic routes are discoverable by the Nitro crawler. The crawler starts from the root route ('/') and follows links to other pages. If your dynamic pages are not linked from discoverable pages, they won't be automatically pre-rendered Nuxt Docs - Prerendering (https://nuxt.com/docs/getting-started/prerendering). 5. You can manually specify routes to be pre-rendered in your nuxt.config.ts file:
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ["/user/1", "/user/2"],
crawlLinks: true,
},
},
});
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ["/user/1", "/user/2"],
crawlLinks: true,
},
},
});
This will pre-render the specified routes and crawl for links Nuxt Docs - Prerendering (https://nuxt.com/docs/getting-started/prerendering). 6. If you're using a custom server route for your sitemap, make sure it's properly configured to include all your dynamic routes. If you've tried these steps and are still having issues, you might need to provide more details about your specific setup and configuration for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@565461230060306432> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Sagar Kapoor
Sagar KapoorOP4w ago
@kapa.ai How do I configure Nuxt sitemap to index static file-based dynamic pages located in my pages directory without using an API?
kapa.ai
kapa.ai4w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To configure Nuxt sitemap to index static file-based dynamic pages located in your pages directory without using an API, you can follow these steps: 1. First, ensure you're using Nuxt 3 and have the @nuxtjs/sitemap module installed. 2. In your nuxt.config.ts file, you need to configure the Nitro prerender options to crawl all the links and include your dynamic pages. Here's how you can do it:
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/'],
},
},
})
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/'],
},
},
})
This configuration tells Nitro to start crawling from the root route ('/') and follow all the links it finds Nuxt Docs - Prerendering (https://nuxt.com/docs/getting-started/prerendering). 3. If you have any dynamic pages that are not linked from other pages (and thus not discoverable by the crawler), you can manually add them to the routes array:
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/dynamic-page-1', '/dynamic-page-2'],
},
},
})
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/dynamic-page-1', '/dynamic-page-2'],
},
},
})
4. To ensure the sitemap is generated during the build process, you should add it to the prerender routes as well:
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/sitemap.xml'],
},
},
})
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/sitemap.xml'],
},
},
})
This will make sure that your sitemap is generated and includes all the crawled routes Nuxt Content Docs - Sitemap (https://content.nuxt.com/recipes/sitemap/#server-route). 5. If you're using the @nuxtjs/sitemap module, make sure it's properly configured in your nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'@nuxtjs/sitemap'
],
sitemap: {
hostname: '<https://your-domain.com',>
},
})
export default defineNuxtConfig({
modules: [
'@nuxtjs/sitemap'
],
sitemap: {
hostname: '<https://your-domain.com',>
},
})
Remember that the sitemap module should be declared last in the modules array to ensure it includes routes created by other modules Nuxt Content V1 Docs - @nuxtjs/sitemap (https://content.nuxt.com/v1/community/integrations/#nuxtjssitemap). By following these steps, Nuxt should be able to generate a sitemap that includes your static file-based dynamic pages without the need for an API. The Nitro crawler will discover all linked pages in your site structure, and any additional routes you specify will be included as well. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@565461230060306432> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Sagar Kapoor
Sagar KapoorOP4w ago
@kapa.ai You can either prerender these pages and they'll be discovered automatically or setup an endpoint which returns them How to do this?
kapa.ai
kapa.ai4w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the information provided in the knowledge sources, I can explain how to prerender pages for automatic discovery or set up an endpoint to return them in Nuxt. Let's look at both approaches: 1. Prerendering pages for automatic discovery: To prerender pages so they'll be discovered automatically, you can use Nuxt's built-in prerendering capabilities. Here's how to configure it in your nuxt.config.ts:
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/'],
},
},
})
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/'],
},
},
})
This configuration tells Nitro (Nuxt's server engine) to start crawling from the root route ('/') and follow all the links it finds Nuxt Docs - Prerendering (https://nuxt.com/docs/getting-started/prerendering). If you have pages that are not linked from other pages, you can manually add them to the routes array:
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/dynamic-page-1', '/dynamic-page-2'],
},
},
})
export default defineNuxtConfig({
nitro: {
prerender: {
crawlLinks: true,
routes: ['/', '/dynamic-page-1', '/dynamic-page-2'],
},
},
})
2. Setting up an endpoint to return pages: To set up an endpoint that returns your pages, you can create a server route. Here's an example of how to do this for a sitemap, which you can adapt for your needs: 1. Create a file server/routes/sitemap.xml.ts (this will create a /sitemap.xml endpoint):
import { serverQueryContent } from '#content/server'
import { SitemapStream, streamToPromise } from 'sitemap'

export default defineEventHandler(async (event) => {
// Fetch all documents
const docs = await serverQueryContent(event).find()
const sitemap = new SitemapStream({
hostname: '<https://example.com'>
})

for (const doc of docs) {
sitemap.write({
url: doc._path,
changefreq: 'monthly'
})
}
sitemap.end()

return streamToPromise(sitemap)
})
import { serverQueryContent } from '#content/server'
import { SitemapStream, streamToPromise } from 'sitemap'

export default defineEventHandler(async (event) => {
// Fetch all documents
const docs = await serverQueryContent(event).find()
const sitemap = new SitemapStream({
hostname: '<https://example.com'>
})

for (const doc of docs) {
sitemap.write({
url: doc._path,
changefreq: 'monthly'
})
}
sitemap.end()

return streamToPromise(sitemap)
})
2. Make sure to prerender this endpoint in your nuxt.config.ts:
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ['/sitemap.xml']
}
}
})
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ['/sitemap.xml']
}
}
})
This example is specifically for a sitemap Nuxt Content Docs - Sitemap (https://content.nuxt.com/recipes/sitemap/#server-route), but you can modify it to return your pages in whatever format you need. Remember, if you're using Nuxt's static site generation (nuxt generate), you'll need to ensure that your dynamic routes are either discoverable through links or explicitly added to the prerender routes Stack Overflow - Nuxt 3 SSG pages (https://stackoverflow.com/questions/77292506). By using either of these methods, you should be able to ensure that all your pages, including dynamic ones, are discoverable and included in your site's structure. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@565461230060306432> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server