Next.js Discord

Discord Forum

Localize Sitemap

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Netherland DwarfOP
Base on nextjs docs, we can use https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-localized-sitemap but when i try to run, the output is not xml (image) but if i remove alternates, i get the xml output

8 Replies

Netherland DwarfOP
exactly the same code

import { MetadataRoute } from 'next'

export default function sitemap(): MetadataRoute.Sitemap {
    return [
        {
            url: 'https://acme.com',
            lastModified: new Date(),
            alternates: {
                languages: {
                    'en': 'https://acme.com',
                },
            },
        },
        {
            url: 'https://acme.com/about',
            lastModified: new Date(),
            alternates: {
                languages: {
                    es: 'https://acme.com/es/about',
                    de: 'https://acme.com/de/about',
                },
            },
        },
        {
            url: 'https://acme.com/blog',
            lastModified: new Date(),
            alternates: {
                languages: {
                    es: 'https://acme.com/es/blog',
                    de: 'https://acme.com/de/blog',
                },
            },
        },
    ]
}
Netherland DwarfOP
[UPDATE] : Might be jsut output issue but if view source it works!
do you have fixed?
does anyone else have this problem?
@onliner do you have fixed?
Netherland DwarfOP
it seems like its just a viewing issue that looks like the SS, but if you view source everything is working fine.
@Netherland Dwarf it seems like its just a viewing issue that looks like the SS, but if you view source everything is working fine.
heyy thanks for you reply but it's not true, google don't detect the url