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
Was this helpful?
This example creates an after sitemap hook on the myRouter
prefix.
1// In routers.js23export function myRouter_afterSitemap(sitemapRequest, sitemapEntries) {4 // after sitemap code ...5}6
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.
1// In routers.js23import {WixRouterSitemapEntry} from 'wix-router';45export 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