> 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`). > - 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`](wix-router.WixRouterSitemapRequest.html) 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; } ``` ---