The MetadataRoute.Sitemap in NextJs is missing a definition for alternates

The issue at hand

My current task involves generating a sitemap with hreflang links for different languages. Following the guidelines provided in the NextJs documentation (https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-localized-sitemap), I have attempted to create a sitemap with alternate URLs, or hreflangs, as shown below:

import { MetadataRoute } from 'next';

export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://example.com',
lastModified: new Date(),
alternates: {
languages: {
es: 'https://example.com/es',
de: 'https://example.com/de',
},
},
},...]}

Expected outcome

The desired result should be an XML structure as follows:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">   
<url>    
 <loc>https://example.com</loc>     
<xhtml:link  rel="alternate" hreflang="es" href="https://example.com/es"/>     
<xhtml:link  rel="alternate" hreflang="de" href="https://example.com/de"/>     
<lastmod>2023-04-06T15:02:24.021Z</lastmod>   
</url>

However, it seems that the MetadaRoute.Sitemap object does not incorporate a definition for alternates. Upon implementing the provided code snippet, or my own version, I am able to retrieve the <loc> and <lastmod> properties but the alternates are missing:

type SitemapFile = Array<{     
url: string;     
lastModified?: string | Date;     
changeFrequency?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';     priority?: 
number; 
}>;

Has anyone encountered and successfully resolved this challenge while generating a sitemap with alternate URLs? My environment includes Next.js version ^14.1.4 and next-intl version ^3.1.0.

Answer №1

My experience mirrors yours - I've encountered the same problem. Despite the sitemap not displaying correctly in some browsers, it is indeed valid.

You can find evidence and further information at this link:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Angular Compilation When Importing Library Function into Web Worker

I am facing an issue with a web worker in Angular that used to function properly in the previous versions: /// <reference lib="webworker" /> import { ParseResult } from "papaparse"; import { readCSV } from '@fireflysemantics/ ...

What are the steps to incorporating mdbootstrap into Angular 2?

For my current project, I am utilizing a date-picker from . How can I implement this date-picker in an Angular 2 component? Do I need to convert the following jQuery code to TypeScript for my component: $('.datepicker').pickadate();? my_componen ...

Attempting to clean but no success in the process

Currently, I am attempting to sanitize an HTML string before sending it to the database. I have implemented the sanitize-html npm package for this purpose, but unfortunately, it is not functioning as intended. if (noteContent) { const resultContent = san ...

Encountering an Error 404 while trying to access an API endpoint in Next.js version 14

I scoured articles and YouTube tutorials in search of a solution to the error 404 I encountered when trying to call an API router such as /api/hello/ Despite consulting the documentation on Next.js website, I couldn't find a fix for this issue. I eve ...

Routing with nested modules in Angular 2 can be achieved by using the same

Encountering a common issue within a backend application. Various resources can be accessed through the following routes: reports/view/:id campains/view/:id suts/view/:id certifications/view/:id Note that all routes end with the same part: /view/:id. ...

Is it necessary to retrieve all data from the database again after inserting just one item?

Currently, I find myself inside a Next.js application with both a form and a list of items. Upon submitting a new item through the form, it gets posted to the database and then appears in the list. My dilemma lies in whether it is more efficient to fetch ...

The file transfer functionality in object FileTransfert is malfunctioning on certain Android devices when attempting to upload

A mobile application was created to facilitate the sharing of items. Users are required to provide information about the item they are sending, along with the option to add a picture of the object. To achieve this functionality, plugins such as cordova f ...

When working with Typescript, NextAuth throws errors while embedding

When attempting to implement NextAuth into my Typescript application, I encounter two errors: one with NextAuth and the other with NextAuthOptions. import NextAuth from "next-auth" import { NextAuthOptions } from "next-auth" import Go ...

Tips for maintaining the selected state of a row using Typescript and the option tag

Here is the code for a dropdown: <div class="col-md-6"> <label for="inertiaStart" style="float: left; width: 17%;">Inertia Start</label> <select ng-model="selectedShiftChannel" style="float: left; width: 70%;height: 26 ...

Refreshing the page in Angular 2 without changing the route page

I am currently working on a Component that displays a list of projects, along with Edit and Delete buttons. When the delete button is clicked: onDelete(projectName: string): void { this.projectService.deleteProject(projectName); this.router.navi ...

Angular dynamic array binding binds to multiple elements rather than just one

In my code, I am working with an array object structured as follows: let myArray=[ { "id":"100", "child1":[ {"id":"xx","Array":[]}, {"id":"yy","Array":[]}, {"id":"zz","Array":[]} ] }, { "id":"200", "child1":[ {"id":"xx","Array ...

Extending parent context in dependencies through OOP/Typescript as an alternative to using "extends"

Introducing a custom class called EventBus has been a game-changer for me. This class allows for easy attachment of on/off/once methods to any class that extends it, enabling the creation of an array of events that can be listened to. Currently, I find my ...

formBuilder does not exist as a function

Description: Using the Form Builder library for react based on provided documentation, I successfully implemented a custom fields feature in a previous project. This project utilized simple JavaScript with a .js extension and achieved the desired result. ...

Can TypeScript use `extends` or `implements` to enforce constructor parameter types?

After conducting thorough research, I have reviewed the following resources: Abstract constructor type in TypeScript How does `type Constructor<T> = Function & { prototype: T }` apply to Abstract constructor types in TypeScript? Abstract ...

Securing user authentication in Spring Boot and NextJs: A guide for managing two distinct user types

I am new to dealing with authentication and finding myself at a standstill on the best, most secure approach. Here's an overview of my current setup: Utilizing Spring Boot for the backend/REST API and NextJs for the frontend. We require two types of ...

SVG is not incorporated in the Typescript build

I'm facing an issue where my build using tsc --project tsconfig.dist.json (refer to the file below) does not include the assets (.svg files) that are imported and used in the code. How can I make TypeScript include these assets in the build? Some con ...

Effortless transfer of a module from one TypeScript file to another

I'm facing an issue with importing classes from one .ts file to another .ts file. Here is the structure of my project: https://i.sstatic.net/gZM57.png I'm attempting to import print.ts into testing.ts This is how my tsconfig.json appears: ht ...

Showing error messages in Angular when a form is submitted and found to be invalid

My form currently displays an error message under each field if left empty or invalid. However, I want to customize the behavior of the submit button when the form is invalid. <form #projectForm="ngForm" (ngSubmit)="onSubmit()"> ...

Ways to retrieve the identifier of a specific element within an array

After successfully retrieving an array of items from my database using PHP as the backend language, I managed to display them correctly in my Ionic view. However, when I attempted to log the id of each item in order to use it for other tasks, it consistent ...

Guide to implementing ion-toggle for notifications with Ionic 2 and Angular 2

Currently, I am using a toggle icon to set the notification as active or inactive. The response is obtained from a GET call. In the GET call, the notification value is either 0 or 1, but in my TypeScript file, I am using noteValue as boolean, which means w ...