Skip to content

Commit

Permalink
docs: Fix sitemap example (resolves #1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Oct 22, 2024
1 parent 04106a1 commit 5a8c1ae
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,15 @@ export default async function manifest(): Promise<MetadataRoute.Manifest> {

### Sitemap

If you're using a sitemap to inform search engines about all pages of your site, you can attach [locale-specific alternate entries](https://developers.google.com/search/docs/specialty/international/localized-versions#sitemap) to every URL in the sitemap to indicate that a particular page is available in multiple languages or regions.
If you're using a sitemap to inform search engines about all pages of your site, you can attach locale-specific [alternate entries](https://developers.google.com/search/docs/specialty/international/localized-versions#sitemap) to every URL in the sitemap to indicate that a particular page is available in multiple languages or regions.

Note that by default, `next-intl` returns [the `link` response header](/docs/routing#alternate-links) to instruct search engines that a page is available in multiple languages. While this sufficiently links localized pages for search engines, you may choose to provide this information in a sitemap in case you have more specific requirements.

Next.js supports providing alternate URLs per language via the [`alternates` entry](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-localized-sitemap) as of version 14.2. You can use your default locale for the main URL and provide alternate URLs based on all locales that your app supports. Keep in mind that also the default locale should be included in the `alternates` object.

```tsx filename="app/sitemap.ts" {5-6,9-10}
```tsx filename="app/sitemap.ts" {4-5,8-9}
import {MetadataRoute} from 'next';
import {routing} from '@/i18n/routing';
import {getPathname} from '@/i18n/routing';
import {routing, getPathname} from '@/i18n/routing';

// Adapt this as necessary
const host = 'https://acme.com';
Expand All @@ -182,7 +181,7 @@ function getEntry(href: Href) {

function getUrl(href: Href, locale: (typeof routing.locales)[number]) {
const pathname = getPathname({locale, href});
return `${host}/${locale}${pathname === '/' ? '' : pathname}`;
return host + pathname;
}
```

Expand Down

0 comments on commit 5a8c1ae

Please sign in to comment.