Nextjs Sitemaps
Unanswered
English Springer Spaniel posted this in #help-forum
English Springer SpanielOP
Are there any good methods for generating a sitemap and a sitemap index file?
20 Replies
English Springer SpanielOP
Yeah, I've tried using this one, unfortunately it doesn't pick up ISR based routes that use getStaticPaths.
English Springer SpanielOP
I'll see if that works, if it doesn't then I guess I'll have to hard code this stuff 😦
it should work, I have done it before
just like how you get the path in
getStaticPathsyou could ask here if you can't get it work
English Springer SpanielOP
Right, I've used that package for the old router and it worked great for ISR and Static Routes.
But now, it doesn't pick up those pre generated paths automatically or even non dynamic paths like the "/" page. So those are pages that I'd need to hardcode into the generation of the sitemap.
Nextjs also doesn't seem to have a built in method for creating your own sitemap and easily linking them together.
But now, it doesn't pick up those pre generated paths automatically or even non dynamic paths like the "/" page. So those are pages that I'd need to hardcode into the generation of the sitemap.
Nextjs also doesn't seem to have a built in method for creating your own sitemap and easily linking them together.
Maybe I'm just getting stuck on something that's not that important, it just seems weird that these other non dynamic routes aren't picked up and added to the sitemap.
English Springer SpanielOP
@Ray I appreciate the help! Do you know if there's any way to do this statically?
Thanks ahead of time!
Thanks ahead of time!
@English Springer Spaniel <@743561772069421169> I appreciate the help! Do you know if there's any way to do this statically?
Thanks ahead of time!
are you trying to work with the sitemap on page router or app router?
English Springer SpanielOP
@Ray app router ðŸ‘
@English Springer Spaniel <@743561772069421169> app router ðŸ‘
oh then you could use sitemap.(js|ts) for it
English Springer SpanielOP
Unfortunately not being able to easily create a linking between different sitemaps, or rather a sitemap index file with the existing nextjs implementation has led me to fallback to the next-sitemap package. But neither really accomplish what I'd like.
I've resorted to hardcoding the non dynamic routes like so:
I've resorted to hardcoding the non dynamic routes like so:
var BASE_URL = process.env.VERCEL_URL || "http://localhost:3000";
/** @type {import("next-sitemap").IConfig} */
module.exports = {
siteUrl: BASE_URL,
generateRobotsTxt: true,
generateIndexSitemap: true,
exclude: ["/server-sitemap-index.xml", "/server-sitemaps/**/*"], // <= exclude here
additionalPaths: async (config) => {
const transformedPaths = await Promise.all([
await config.transform(config, `/`),
await config.transform(config, "/contact"),
await config.transform(config, "/contact/advertising"),
await config.transform(config, "/contact/seo"),
await config.transform(config, "/contact/website"),
await config.transform(config, "/insights"),
await config.transform(config, "/services"),
await config.transform(config, "/about"),
await config.transform(config, "/projects"),
]);
return transformedPaths;
},
robotsTxtOptions: {
additionalSitemaps: [
`${BASE_URL}/server-sitemap-index.xml`, // <==== Add here
],
},
};we have full control on how should the sitemap look like, isn't it good?
if all the route are included automatically, then you might wonder how to exclude a route