Sitemap
Unanswered
Zepeto posted this in #help-forum
ZepetoOP
Is it possible to retrieve the current route slug from the sitemap ?
And is the sitemap executed in the build or the runtime?
/[slug]/sitemap.xmlAnd is the sitemap executed in the build or the runtime?
8 Replies
@Zepeto 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?
Sitemap is not executed. Its used by bots. If you are dynamically generating it, its available on both development and build.
Refer to:
https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-multiple-sitemaps
Refer to:
https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-multiple-sitemaps
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.
ZepetoOP
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
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(),
}));
}Tried to access this http://localhost:3000/sitemap.xml/john-doe
ZepetoOP
Up