wix-router.WixRouterRequest

wix-router.WixRouterRequest

An object representing an incoming page request received by a router.

The WixRouterRequest object breaks the URL of the incoming router request into different parameters for easy access.

Premium Sites

Given the premium site router request: https://domain.com/animals/mammals/elephant?species=african-elephant#desc, the URL is broken down as shown in the table below:

url
baseUrl
protocol host prefix path query hash
https :// domain.com /animals /mammals/elephant ? species=african-elephant # desc

Free Site

Given the free site URL: https://user.wixsite.com/zoo/animals/mammals/elephant?species=african-elephant#desc, the URL is broken down as shown in the table below:

url
baseUrl
protocol host site prefix path query hash
https :// user.wixsite.com / zoo /animals /mammals/elephant ? species=african-elephant # desc

Contents

baseUrl Returns the base URL of the router request.
formFactor Returns the form factor of the device used to make the router request.
ip Returns the remote IP address of the router request.
pages Returns the names of the pages associated with this router.
path Returns the path of the router request URL.
prefix Returns the router prefix of the router request URL.
protocol Returns the protocol of the router request URL.
query Returns the query fields and values of the request URL.
referrer Returns the referrer header from the router request.
url Returns the full URL of the router request.
user Returns the details of the current site user who is logged in.
userAgent Returns the user-agent header as sent from the device used to make the router request.
baseUrl

baseUrl

Returns the base URL of the router request.

Syntax

get baseUrl(): string

Description

Premium sites: Premium site baseUrl

Free sites: Free site baseUrl

Type

String

Examples

Get the base URL of the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBiYXNlVXJsID0gcmVxdWVzdC5iYXNlVXJsOwogIC8vIFByZW1pdW0gc2l0ZTogImh0dHBzOi8vZG9tYWluLmNvbS8iCiAgLy8gRnJlZSBzaXRlOiAiaHR0cHM6Ly91c2VyLndpeC1zaXRlcy5jb20vem9vLyIKCn0K
export function myRouter_Router(request) {

  let baseUrl = request.baseUrl;
  // Premium site: "https://domain.com/"
  // Free site: "https://user.wix-sites.com/zoo/"

}
formFactor

formFactor

Returns the form factor of the device used to make the router request.

Syntax

get formFactor(): string

Description

Returns either desktop or mobile.

Type

String

Examples

Get the form factor of the device used to make the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBmb3JtRmFjdG9yID0gcmVxdWVzdC5mb3JtRmFjdG9yOyAvLyAiZGVza3RvcCIKCn0K
export function myRouter_Router(request) {

  let formFactor = request.formFactor; // "desktop"

}
ip

ip

Returns the remote IP address of the router request.

Syntax

get ip(): string

Type

String

Examples

Get the IP of the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBpcCA9IHJlcXVlc3QuaXA7IC8vICIzNC4yMzIuMzQuMjQyIgoKfQo=
export function myRouter_Router(request) {

  let ip = request.ip; // "34.232.34.242"

}
pages

pages

Returns the names of the pages associated with this router.

Syntax

get pages(): string[]

Description

Pages are added and removed from a router in the Editor. The page names returned by the pages property can be used when returning a router response (e.g. ok('page-name', ...)).

Type

String[ ]

Examples

Get the names of the pages associated with this router

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBwYWdlcyA9IHJlcXVlc3QucGFnZXM7CiAgLy8gWyJteVJvdXRlci1wYWdlMSIsICJteVJvdXRlci1wYWdlMiJdCgp9Cg==
export function myRouter_Router(request) {

  let pages = request.pages;
  // ["myRouter-page1", "myRouter-page2"]

}
path

path

Returns the path of the router request URL.

Syntax

get path(): string[]

Description

Premium sites: Premium site path

Free sites: Free site path

Type

String[ ]

Examples

Get the path of the router request's URL

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBwYXRoID0gcmVxdWVzdC5wYXRoOyAvLyBbIm1hbW1hbHMiLCAiZWxlcGhhbnQiXQoKfQo=
export function myRouter_Router(request) {

  let path = request.path; // ["mammals", "elephant"]

}
prefix

prefix

Returns the router prefix of the router request URL.

Syntax

get prefix(): string

Description

Premium sites: Premium site prefix

Free sites: Free site prefix

Type

String

Examples

Get the prefix of the router request's URL

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBwcmVmaXggPSByZXF1ZXN0LnByZWZpeDsgLy8gImFuaW1hbHMiCgp9Cg==
export function myRouter_Router(request) {

  let prefix = request.prefix; // "animals"

}
protocol

protocol

Returns the protocol of the router request URL.

Syntax

get protocol(): string

Description

Premium sites: Premium site protocol

Free sites: Free site protocol

Type

String

Examples

Get the protocol of the router request's URL

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBwcm90b2NvbCA9IHJlcXVlc3QucHJvdG9jb2w7IC8vICJodHRwcyIKCn0K
export function myRouter_Router(request) {

  let protocol = request.protocol; // "https"

}
query

query

Returns the query fields and values of the request URL.

Syntax

get query(): Object

Description

Premium sites: Premium site query

Free sites: Free site query

Type

Object

Examples

Get the query of the router request's URL

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCBxdWVyeSA9IHJlcXVlc3QucXVlcnk7CiAgLy8geyJzcGVjaWVzIjogImFmcmljYW4tZWxlcGhhbnQifQp9Cg==
export function myRouter_Router(request) {

  let query = request.query;
  // {"species": "african-elephant"}
}
referrer

referrer

Returns the referrer header from the router request.

Syntax

get referrer(): string

Description

The referrer is the address of the web page from which the router request was initiated, typically by clicking on a link.

Type

String

Examples

Get the referrer header from the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCByZWZlcnJlciA9IHJlcXVlc3QucmVmZXJyZXI7CiAgLy8gImh0dHA6Ly9zb21lc2l0ZS5jb20iCgp9Cg==
export function myRouter_Router(request) {

  let referrer = request.referrer;
  // "http://somesite.com"

}
url

url

Returns the full URL of the router request.

Syntax

get url(): string

Description

Premium sites: Premium site URL

Free sites: Free site URL

Type

String

Examples

Get the URL of the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCB1cmwgPSByZXF1ZXN0LnVybDsKICAvLyBQcmVtaXVtIHNpdGU6CiAgLy8gImh0dHBzOi8vZG9tYWluLmNvbS9hbmltYWxzL21hbW1hbHMvZWxlcGhhbnQ/c3BlY2llcz1hZnJpY2FuLWVsZXBoYW50IgogIC8vIEZyZWUgc2l0ZToKICAvLyAiaHR0cHM6Ly91c2VyLndpeC1zaXRlcy5jb20vem9vL2FuaW1hbHMvbWFtbWFscy9lbGVwaGFudD9zcGVjaWVzPWFmcmljYW4tZWxlcGhhbnQiCgp9Cg==
export function myRouter_Router(request) {

  let url = request.url;
  // Premium site:
  // "https://domain.com/animals/mammals/elephant?species=african-elephant"
  // Free site:
  // "https://user.wix-sites.com/zoo/animals/mammals/elephant?species=african-elephant"

}
user

user

Returns the details of the current site user who is logged in.

Syntax

get user(): WixRouterUser

Description

Returns an object with the id and role of the logged in user who made the router request.

Type

WixRouterUser

Examples

Get the user from the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCB1c2VyID0gcmVxdWVzdC51c2VyOwogIC8qCiAgKiB7CiAgKiAgICJpZCI6ICJmNnEwZmIzMi1iMDZyLTQ2OWYtYWc0ZC05ZGY4OWFma2o1ZDkiLAogICogICAicm9sZSI6ICJBZG1pbiIKICAqIH0KICAqLwp9Cg==
export function myRouter_Router(request) {

  let user = request.user;
  /*
  * {
  *   "id": "f6q0fb32-b06r-469f-ag4d-9df89afkj5d9",
  *   "role": "Admin"
  * }
  */
}
userAgent

userAgent

Returns the user-agent header as sent from the device used to make the router request.

Syntax

get userAgent(): string

Type

String

Examples

Get the user-agent header of the device used to make the router request

ZXhwb3J0IGZ1bmN0aW9uIG15Um91dGVyX1JvdXRlcihyZXF1ZXN0KSB7CgogIGxldCB1c2VyQWdlbnQgPSByZXF1ZXN0LnVzZXJBZ2VudDsKICAvLyAiTW96aWxsYS81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTBfMTJfNCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzU3LjAuMjk4Ny4xMzMgU2FmYXJpLzUzNy4zNiIKCn0K
export function myRouter_Router(request) {

  let userAgent = request.userAgent;
  // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

}