> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: sitemap(request: WixRouterSitemapRequest)

# Method package: wixRouter

# Method menu location: wixRouter --> sitemap

# Method Link: https://dev.wix.com/docs/velo/events-service-plugins/routers/service-plugins/wix-router/sitemap.md

# Method Description:

Function containing sitemap logic for a given URL prefix.

The `sitemap()` function handles sitemap requests for pages with the specified
 URL [prefix](#prefixes). Use this function to make sure search engines can find the links
 to your router's pages.

 The `sitemap()` function is not a function that you call from your code. You define
 the function in a file named **routers.js** in the Code File's Backend section of the [Velo Sidebar](https://dev.wix.com/docs/develop-websites/articles/workspace-tools/velo-workspace/workspaces/wix-editor-working-with-the-code-sidebar.md). The
 function is called when a sitemap request is received for the router with the
 specified prefix.

 The function receives a [`WixRouterSitemapRequest`](https://dev.wix.com/docs/velo/events-service-plugins/routers/service-plugins/wix-router/wix-router-sitemap-request/base-url.md)
 object containing information about the incoming sitemap request.

 The function returns an array of [`WixRouterSitemapEntry`](https://dev.wix.com/docs/velo/events-service-plugins/routers/service-plugins/wix-router/wix-router-sitemap-entry.md)
 objects each of which includes information about a page, such as its URL, title, and name.

 To create sitemap entry objects, first import [`WixRouterSitemapEntry`](https://dev.wix.com/docs/velo/events-service-plugins/routers/service-plugins/wix-router/wix-router-sitemap-entry.md)
 from [`wix-router`](https://dev.wix.com/docs/velo/api-reference/wix-router/introduction.md):

 ```javascript
 import {WixRouterSitemapEntry} from "wix-router";
 ```

 The `sitemap()` function is also used to populate the items preview widget,
 allowing you to switch between URLs in preview mode.

> **Note:** The `sitemap()` function also runs when you navigate to a router page in the Editor.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Sitemap stub

```javascript
// In routers.js

export function myRouter_SiteMap(sitemapRequest) {
  // sitemap code ...
}

```

## Basic sitemap

```javascript
// In routers.js

import {WixRouterSitemapEntry} from 'wix-router';

export function myRouter_SiteMap(sitemapRequest) {

	let siteMapEntries = [];

  // Create a sitemap entry for each item
  for (var key in myData) {
    let entry = new WixRouterSitemapEntry();
    entry.pageName = "myRouter-page";
    entry.url = "/myRouter/" + key;
    entry.title = myData[key].title;
    siteMapEntries.push(entry);
  }

  // Return the sitemap entries
  return siteMapEntries;
}

```

## A sitemap with static data

```javascript
// In routers.js

import {WixRouterSitemapEntry} from 'wix-router';

// Sample data
const peopleData = {
   "Ash": {
     title:     "Ash Stowe",
     imageSite: "https://static.wixstatic.com/media/",
     image:     "b8f383e0fe2b478ea91362b707ef267b.jpg"
    },
   "Aiden": {
    title:      "Aiden Johnson",
    imageSite:  "https://static.wixstatic.com/media/",
    image:      "ca3c7ac5427e43928aa5f3f443ae2163.jpg"
   },
   "Jess": {
    title:      "Jess White",
    imageSite:  "https://static.wixstatic.com/media/",
    image:      "147fe6f37fe24e83977b4124e41b6d3d.jpg"

   },
   "Morgan": {
    title:      "Morgan James",
    imageSite:  "https://static.wixstatic.com/media/",
    image:      "59e1f2f4dbbc4f7c9d6e66e3e125d830.jpg"
   }
};

export function myRouter_SiteMap(sitemapRequest) {

  //Convert the data to sitemap entries
  const siteMapEntries = Object.keys(peopleData).map( (name) => {
    const data = peopleData[name];
    const entry = new WixRouterSitemapEntry(name);
    entry.pageName = "myRouter-page";
    entry.url = `/myRouter/${name}`;
    entry.title = data.title;
    return entry;
  } );

  // Return the sitemap entries
  return siteMapEntries;
}

```

## A sitemap with collection data

```javascript
// Place this code in the routers.js file
// of your site's Backend section.

import wixData from 'wix-data';
import { WixRouterSitemapEntry } from 'wix-router';

export async function myRouter_SiteMap(sitemapRequest) {

  // Retrieve the sitemap data from a collection.
  const results = await wixData.query('mySitemapProperties').find()
  const properties = results.items

  // Convert the data to site map entries.
  const sitemapEntries = properties.map(property => {
    const entry = new WixRouterSitemapEntry(property.title);
    entry.pageName = 'myRouter-page';
    entry.url = '/myRouter/' + property.slug;
    entry.title = property.title;
    return entry;
    });

  // Return the site map entries.
  return sitemapEntries;
}
```

## Build a sitemap for the `helloworld` prefix

```javascript
// Place this code in the routers.js file
// of your site's Backend section.

import {WixRouterSitemapEntry} from "wix-router";
import wixData from 'wix-data';


export async function helloworld_SiteMap(sitemapRequest) {
  const { items: greetings } = await wixData.query('Greetings').find();

  // Convert the data to site map entries
  const siteMapEntries = greetings.map(greeting => {
    const entry = new WixRouterSitemapEntry(greeting.title);
    entry.pageName = 'item-page'; // The name of the page in the Wix editor to render
    entry.url = '/helloworld/' + greeting.slug; // Relative URL of the page
    entry.title = greeting.title; // For better SEO - Help Google
    return entry;
  });

  const indexEntry = new WixRouterSitemapEntry('Greetings Index');
  indexEntry.pageName = 'index-page'; // The name of the page in the Wix editor to render
  indexEntry.url = '/helloworld' // Relative URL of the page
  indexEntry.title = 'Greetings Index'; // For better SEO - Help Google

  siteMapEntries.push(indexEntry);

  // Return the site map entries
  return siteMapEntries;
}
```

---