CodeAPI

wix-site

The wix-site module contains functionality for obtaining information about your site and its pages.

To use the site module, import wixSite from the wix-site module:

   import wixSite from 'wix-site';

The APIs in wix-site can only be used in front-end code.

Table of Contents

FUNCTIONS

?
Perform actions on an object.
getSiteStructure( )Returns information about the site's pages, prefixes, and lightboxes.
routerSitemap( )Returns the sitemap for a router or dynamic page prefix.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
PrefixAn object that contains information about the site's prefixes.
SiteStructureAn object that contains information about the site's pages, prefixes, and lightboxes.
StructureLightboxAn object that contains information about a lightbox on the site.
StructurePageAn object that contains information about a page on the site.

getSiteStructure( )

Returns information about the site's pages, prefixes, and lightboxes.

See Also

currentPage

Syntax

function getSiteStructure(): SiteStructure
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
An object that contains information about the site's pages, prefixes, and lightboxes.

Examples

Get information about the site's pages, prefixes, and lightboxes

This example gets the structure of the site with the following in its pages menu:

import wixSite from 'wix-site';

// ...

let structure = wixSite.getSiteStructure();

/*
* {
*   "pages": [
*     {
*       "name": "Home",
*    	  "type": "static",
*    	  "url": "/home",
*    	  "isHomePage": true
*  	 },
*  	 {
*       "name": "Page 1",
*       "type": "static",
*    	  "url:" /page-1"
*  	 },
*  	 {
*    	  "name": "Page 2",
*    	  "type": "static",
*    	  "url": "/page-2"
*  	 },
*  	 {
*    	  "name": "Parent Page",
*    	  "type": "static",
*    	  "url": "/parent-page"
*    },
*  	 {
*    	  "name": "Child Page",
*    	  "type": "static",
*    	  "url": "/child-page"
*  	 },
*  	 {
*    	  "name": "router-page",
*    	  "type": "template",
*    	  "prefix": "router"
*  	 },
*  	 {
*    	  "name": "MyCollection (Title)",
*    	  "type": "template",
*    	  "prefix": "MyCollection"
*    },
*  	 {
*    	  "name": "MyCollection (All)",
*    	  "type": "template",
*    	  "prefix": "MyCollection"
*  	 },
*  	 {
*    	  "name": "Dashboard Page",
*    	  "type": "static"
*    },
*  	 {
*    	  "name": "Shop",
*    	  "type": "template",
*    	  "url": "/shop",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Product Page",
*    	  "type": "template",
*    	  "url": "/product-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*    {
*    	  "name": "Thank You Page",
*    	  "type": "template",
*    	  "url": "/thank-you-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Cart",
*    	  "type": "template",
*    	  "url": "/cart",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*       "name": "Members",
*    	  "type": "template",
*    	  "url": "/members",
*    	  "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
*  	 }
* ],
*   "prefixes": [
*  	 {
*       "name": "router",
*    	  "type": "router",
*    	  "prefix": "/router"
*  	 },
*  	 {
*    	  "name": "MyCollection",
*    	  "type": "dynamicPages",
*    	  "prefix": "/MyCollection"
*  	 },
*  	 {
*    	  "name": "MyCollection",
*    	  "type": "dynamicPages",
*    	  "prefix": "/MyCollection"
*  	 },
*  	 {
*    	  "name": "Shop",
*    	  "type": "app",
*    	  "prefix: "/shop",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Product Page",
*    	  "type": "app",
*    	  "prefix": "/product-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Thank You Page",
*    	  "type": "app",
*    	  "prefix": "/thank-you-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Cart",
*    	  "type": "app",
*    	  "url": "/cart",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*       "name": "Members",
*    	  "type": "app",
*    	  "prefix": "/members",
*    	  "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
*  	 }
*  ],
*	  "lightboxes": [
*  	  {
*  	     "name": "Welcome (Full Screen)"
*     }
*   ]
* }
*/

routerSitemap( )

Returns the sitemap for a router or dynamic page prefix.

Description

The routerSitemap() function returns a Promise that resolves to a list of WixSitemapEntry objects. Each WixSitemapEntry includes information about a page, such as its URL, title, and name.

A sitemap is used by search engines to find the links to the site's pages.

Syntax

function routerSitemap(routerPrefix: string): Promise<Array<WixRouterSitemapEntry>>
PARAMETERS
?
Values that you pass to a function.
routerPrefix
string
The prefix of the router to get the sitemap for.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Array<WixRouterSitemapEntry>>

Fulfilled - A list of sitemap entries. Rejected - The error that caused the rejection.

Examples

Get the sitemap for a prefix

import wixSite from 'wix-site';

// ...

wixSite.routerSitemap("routerPrefix")
  .then( (routerSitemap) => {
    let sitemap = routerSitemap;
  } );

/*
 * sitemap:
 *
 * [
 *   {
 *   	"url": "Ash",
 *   	"lastModified": null,
 *   	"changeFrequency": "",
 *   	"priority": null,
 *   	"title": "Ash Stowe",
 *   	"pageName": "Ash's Page"
 *   },
 *   {
 *   	"url": "Aiden",
 *   	"lastModified": null,
 *   	"changeFrequency": "",
 *   	"priority": null,
 *   	"title": "Aiden Johnson",
 *   	"pageName": "Aiden's page"
 *   },
 *   {
 *   	"url": "Jess",
 *   	"lastModified": null,
 *   	"changeFrequency": "",
 *   	"priority": null,
 *   	"title": "Jess White",
 *   	"pageName": "Jess's page"
 *   },
 *   {
 *   	"url": "Morgan",
 *   	"lastModified": null,
 *   	"changeFrequency": "",
 *   	"priority": null,
 *   	"title": "Morgan James",
 *   	"pageName": "Morgan's Page"
 *   }
 * ]
 */

Prefix

An object that contains information about the site's prefixes.

Description

A site's routers, dynamic pages, and app pages all have prefixes.

See Also

SiteStructure, currentPage, getSiteStructure( )

Syntax

type Prefix = {
  name: string
  type: string
  prefix: string
  applicationId: string
}
MEMBERS
?
The properties of an object.
name
string
The name of the prefix.
type
string
The type of the prefix: "dynamicPages", "router", or "app".
prefix
string
The prefix.
applicationId(Optional)
string
If the prefix is an app's prefix, the applicationId property is the app's ID.

Examples

Get information about the site's prefixes

This example gets the prefixes of the site with the following in its pages menu:

import wixSite from 'wix-site';

// ...

let structure = wixSite.getSiteStructure();
let prefixes = structure.prefixes;

/*
 *  prefixes:
 *
 * [
 *   {
 *     "name": "router",
 *     "type": "router",
 *     "prefix": "/router"
 *   },
 *   {
 *     "name": "myCollection",
 *     "type": "dynamicPages",
 *     "prefix": "/myCollection"
 *   },
 *   {
 *     "name": "myCollection",
 *     "type": "dynamicPages",
 *     "prefix": "/myCollection"
 *   },
 *   {
 *     "name": "Shop",
 *     "type": "app",
 *     "prefix": "/shop",
 *     "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *     "name": "Product Page",
 *     "type": "app",
 *     "prefix": "/product-page",
 *  	 "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *     "name": "Thank You Page",
 *  	 "type": "app",
 *  	 "prefix": "/thank-you-page",
 *  	 "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *   	 "name": "Cart",
 *  	 "type": "app",
 *  	 "prefix": "/cart",
 *  	 "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *     "name": "Members",
 *     "type": "app",
 *     "prefix": "/members",
 *     "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
 *   }
 * ]
 */

SiteStructure

An object that contains information about the site's pages, prefixes, and lightboxes.

Description

The SiteStructure object is a flattened representation of the site. Use the getSiteStructure() function to get the site's SiteStructure object. The structure does not include the headers and links from the site's Pages menu.

See Also

getSiteStructure( )

Syntax

type SiteStructure = {
  pages: Array<StructurePage>
  prefixes: Array<Prefix>
  lightboxes: Array<StructureLightbox>
}
MEMBERS
?
The properties of an object.
pages
The pages of the site.
prefixes
Array<Prefix>
The prefixes of the site's routers and dynamic pages.
lightboxes
The site's lightboxes.

Examples

Get information about the site's pages, prefixes, and lightboxes

This example gets the structure of the site with the following in its pages menu:

import wixSite from 'wix-site';

// ...

let structure = wixSite.getSiteStructure();

/*
* {
*   "pages": [
*     {
*       "name": "Home",
*    	  "type": "static",
*    	  "url": "/home",
*    	  "isHomePage": true
*  	 },
*  	 {
*       "name": "Page 1",
*       "type": "static",
*    	  "url:" /page-1"
*  	 },
*  	 {
*    	  "name": "Page 2",
*    	  "type": "static",
*    	  "url": "/page-2"
*  	 },
*  	 {
*    	  "name": "Parent Page",
*    	  "type": "static",
*    	  "url": "/parent-page"
*    },
*  	 {
*    	  "name": "Child Page",
*    	  "type": "static",
*    	  "url": "/child-page"
*  	 },
*  	 {
*    	  "name": "router-page",
*    	  "type": "template",
*    	  "prefix": "router"
*  	 },
*  	 {
*    	  "name": "MyCollection (Title)",
*    	  "type": "template",
*    	  "prefix": "MyCollection"
*    },
*  	 {
*    	  "name": "MyCollection (All)",
*    	  "type": "template",
*    	  "prefix": "MyCollection"
*  	 },
*  	 {
*    	  "name": "Dashboard Page",
*    	  "type": "static"
*    },
*  	 {
*    	  "name": "Shop",
*    	  "type": "template",
*    	  "url": "/shop",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Product Page",
*    	  "type": "template",
*    	  "url": "/product-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*    {
*    	  "name": "Thank You Page",
*    	  "type": "template",
*    	  "url": "/thank-you-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Cart",
*    	  "type": "template",
*    	  "url": "/cart",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*       "name": "Members",
*    	  "type": "template",
*    	  "url": "/members",
*    	  "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
*  	 }
* ],
*   "prefixes": [
*  	 {
*       "name": "router",
*    	  "type": "router",
*    	  "prefix": "/router"
*  	 },
*  	 {
*    	  "name": "MyCollection",
*    	  "type": "dynamicPages",
*    	  "prefix": "/MyCollection"
*  	 },
*  	 {
*    	  "name": "MyCollection",
*    	  "type": "dynamicPages",
*    	  "prefix": "/MyCollection"
*  	 },
*  	 {
*    	  "name": "Shop",
*    	  "type": "app",
*    	  "prefix: "/shop",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Product Page",
*    	  "type": "app",
*    	  "prefix": "/product-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Thank You Page",
*    	  "type": "app",
*    	  "prefix": "/thank-you-page",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*    	  "name": "Cart",
*    	  "type": "app",
*    	  "url": "/cart",
*    	  "applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
*  	 },
*  	 {
*       "name": "Members",
*    	  "type": "app",
*    	  "prefix": "/members",
*    	  "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
*  	 }
*  ],
*	  "lightboxes": [
*  	  {
*  	     "name": "Welcome (Full Screen)"
*     }
*   ]
* }
*/

StructureLightbox

An object that contains information about a lightbox on the site.

See Also

SiteStructure, currentPage, getSiteStructure( )

Syntax

type StructureLightbox = {
  name: string
}
MEMBERS
?
The properties of an object.
name
string
The name of the lightbox.

Examples

Get information about the current lightbox

import wixSite from 'wix-site';

// ...

let current = wixSite.currentPage;

/*
 *  {
 *    "name": "Welcome (Full Screen)"
 *    "type": "lightbox"
 *  }
 */

Get information about the site's lightboxes

This example gets the lightboxes of the site with the following in its pages menu:

import wixSite from 'wix-site';

// ...

let structure = wixSite.getSiteStructure();
let lightboxes = structure.lightboxes;

/*
 * lightboxes:
 *
 * [
 *   {
 *      "name": "Welcome (Full Screen)"
 *   }
 * ]
 */

StructurePage

An object that contains information about a page on the site.

Description

The StructurePage object represents a page in the site. The page can be a regular page, dynamic page, router page, or page from an app.

See Also

SiteStructure, getSiteStructure( )

Syntax

type StructurePage = {
  name: string
  type: string
  url: string
  applicationId: string
  prefix: string
  isHomePage: boolean
}
MEMBERS
?
The properties of an object.
name
string
The of the page.
type
string
The type of the page: "static" or "template".
url(Optional)
string
The URL of the page. If the page is a static page the url property is the page's SEO URL.
applicationId(Optional)
string
If the page is an app page, the applicationId property is the app's ID.
prefix(Optional)
string
If the page is a router or dynamic page, the prefix property is the page's prefix.
isHomePage(Optional)
boolean
If the page is the Home page, isHomePage is true. Otherwise, it does not exist.

Examples

Get information about the current page

import wixSite from 'wix-site';

// ...

let current = wixSite.currentPage;

/*
 *  {
 *    "name": "Home",
 *    "type": "static",
 *    "url": "/home",
 *    "isHomePage": true
 *  }
 */

Get information about the site's pages

This example gets the pages of the site with the following in its pages menu:

import wixSite from 'wix-site';

// ...

let structure = wixSite.getSiteStructure();
let pages = structure.pages;

/*
 * pages:
 * [
 *   {
 *      "name": "Home",
 *      "type": "static",
 *    	"url": "/home",
 *    	"isHomePage": true
 *   },
 *   {
 *     "name": "Page 1",
 *     "type": "static",
 *    	"url:" /page-1"
 *   },
 *   {
 *    	"name": "Page 2",
 *    	"type": "static",
 *    	"url": "/page-2"
 *   },
 *   {
 *    	"name": "Parent Page",
 *    	"type": "static",
 *    	"url": "/parent-page"
 *   },
 *   {
 *    	"name": "Child Page",
 *    	"type": "static",
 *    	"url": "/child-page"
 *   },
 *   {
 *    	"name": "router-page",
 *    	"type": "template",
 *    	"prefix": "router"
 *   },
 *   {
 *    	"name": "MyCollection (Title)",
 *    	"type": "template",
 *    	"prefix": "MyCollection"
 *   },
 *   {
 *    	"name": "MyCollection (All)",
 *    	"type": "template",
 *    	"prefix": "MyCollection"
 *   },
 *   {
 *    	"name": "Dashboard Page",
 *    	"type": "static"
 *   },
 *   {
 *    	"name": "Shop",
 *    	"type": "template",
 *    	"url": "/shop",
 *    	"applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *    	"name": "Product Page",
 *    	"type": "template",
 *    	"url": "/product-page",
 *    	"applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *    	"name": "Thank You Page",
 *      "type": "template",
 *    	"url": "/thank-you-page",
 *    	"applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *    	"name": "Cart",
 *    	"type": "template",
 *      "url": "/cart",
 *    	"applicationId": "1380b703-ce81-ff05-f115-39571d94dfcd"
 *   },
 *   {
 *      "name": "Members",
 *      "type": "template",
 *      "url": "/members",
 *      "applicationId": "14ad9202-3dd3-128a-57bd-e5675fd7e313"
 *   }
 * ]
 */