Help routing the Sitemap.xml on nextjs14
Answered
Bald Eagle posted this in #help-forum
Bald EagleOP
root/src/app/public/sitemap.xml
Currently my sitemap is located there
How do i make it so i can see it on site.com/sitemap.xml
Currently my sitemap is located there
How do i make it so i can see it on site.com/sitemap.xml
Answered by Ray
// app/sitemap.ts
import { MetadataRoute } from 'next'
export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://acme.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
},
{
url: 'https://acme.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.5,
},
]
}16 Replies
is your sitemap.xml a static xml file?
Bald EagleOP
Don't the file need to be sitemap.xml?
I read, and asked helped from gpt's
They recommend putting it on public
app/public/sitemap.xml
I tried doing it on src/app/sitemap.tsx
But it's giving error as it's an xml file
I read, and asked helped from gpt's
They recommend putting it on public
app/public/sitemap.xml
I tried doing it on src/app/sitemap.tsx
But it's giving error as it's an xml file
@Ray is your sitemap.xml a static xml file?
Bald EagleOP
Right now yes, but i'm planning to use the api to make it auto update everytime a blog is posted
// app/sitemap.ts
import { MetadataRoute } from 'next'
export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://acme.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
},
{
url: 'https://acme.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.5,
},
]
}Answer
try create this in app/sitemap.ts
https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap
here is the doc for sitemap
here is the doc for sitemap
Bald EagleOP
I just tried this, however it's giving me 404 error
what url you type?
Bald EagleOP
http://localhost:3000/sitemap
does the same too
does the same too
well it should be show in http://localhost:3000/sitemap.xml
can you show a screenshot of your folder structure?
Bald EagleOP
Nevermind, it worked out fine.
Turns out I fiddled with next.config.js
a while ago trying to figure out the sitemap
Turns out I fiddled with next.config.js
a while ago trying to figure out the sitemap
It works now!
Thanks dude
Thanks dude
ah ok 😆