Next.js Discord

Discord Forum

Sitemap

Unanswered
Zepeto posted this in #help-forum
Open in Discord
Is it possible to retrieve the current route slug from the sitemap ? /[slug]/sitemap.xml

And is the sitemap executed in the build or the runtime?

8 Replies

If you read that documentation you can also figure out however you want to use the slug.
@Clown If you read that documentation you can also figure out however you want to use the slug.
I copied the code from the doc and adapted it by changing the id to a string but it doesn't work, I get a 404

https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-multiple-sitemaps
import { MetadataRoute } from 'next';

export async function generateSitemaps() {
  return [{ user: 'john-doe' }];
}

export default async function sitemap({ user }: { user: string }): Promise<MetadataRoute.Sitemap> {
  const products = ['john-doe'];
  return products.map(product => ({
    url: `localhost:3000/users/${user}`,
    lastModified: new Date(),
  }));
}
Did you account for this?
@Clown Did you account for this?
Yup
Up