Search.../

afterSitemap( )

Registers a hook that is called after a sitemap is created.

Description

The afterSitemap hook is a data binding router hook that is triggered after a sitemap is created for the specified router.

The afterSitemap() 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. The function is called as described above.

Use this hook to revise the list of pages in your sitemap. For example, you can add a search page's information to your sitemap.

The function returns an array of WixRouterSitemapEntry objects. Typically the returned array is a modified version of the one the function received.

If the function does not return a WixRouterSitemapEntry array, the array received as the sitemapEntries parameter acts as the router's effective sitemap entries.

Syntax

function afterSitemap(request: WixRouterSitemapRequest, sitemapEntries: Array<wixroutersitemapentry-obj>): WixRouterSitemapEntry

afterSitemap Parameters

NAME
TYPE
DESCRIPTION
request

The sitemap request.

sitemapEntries

The generated sitemap entries.

Returns

Fulfilled - A sitemapEntries array.

Return Type:

Promise<Array<WixRouterSitemapEntry>>

Was this helpful?

After sitemap stub

This example creates an after sitemap hook on the myRouter prefix.

Copy Code
1// In routers.js
2
3export function myRouter_afterSitemap(sitemapRequest, sitemapEntries) {
4 // after sitemap code ...
5}
6
Add a search page to the sitemap

This example creates an after sitemap hook on the myRouter prefix that adds a search page to the sitemap. Note that the sitemap function only publishes a URL for the search page. To actually implement a page at this URL you can use a beforeRouter() hook to check for the request for the search page URL and route the user to a search page.

Copy Code
1// In routers.js
2
3import {WixRouterSitemapEntry} from 'wix-router';
4
5export function myRouter_afterSitemap(sitemapRequest, sitemapEntries) {
6 let prefix = sitemapRequest.prefix;
7 let entry = new WixRouterSitemapEntry(`${prefix}/search`);
8 sitemapEntries.push(entry);
9 return sitemapEntries;
10}
11