CodeAPI

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
protocolhostprefixpathqueryhash
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
protocolhostsiteprefixpathqueryhash
https://user.wixsite.com/zoo/animals/mammals/elephant?species=african-elephant#desc

Table of Contents

PROPERTIES

?
Store values associated with an object.
baseUrlReturns the base URL of the router request.
formFactorReturns the form factor of the device used to make the router request.
ipReturns the remote IP address of the router request.
pagesReturns the names of the pages associated with this router.
pathReturns the path of the router request URL.
prefixReturns the router prefix of the router request URL.
protocolReturns the protocol of the router request URL.
queryReturns the query fields and values of the request URL.
referrerReturns the referrer header from the router request.
urlReturns the full URL of the router request.
userReturns the details of the current site user who is logged in.
userAgentReturns the user-agent header as sent from the device used to make the router request.

baseUrl

Returns the base URL of the router request.

Description

Premium sites:

Free sites:

Syntax

get baseUrl(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the base URL of the router request

export function myRouter_Router(request) {

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

}

formFactor

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

Description

Returns either desktop or mobile.

Syntax

get formFactor(): string
TYPE
?
The kind of data the property stores.
string

Examples

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

export function myRouter_Router(request) {

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

}

ip

Returns the remote IP address of the router request.

Syntax

get ip(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the IP of the router request

export function myRouter_Router(request) {

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

}

pages

Returns the names of the pages associated with this router.

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', ...)).

Syntax

get pages(): Array<string>
TYPE
?
The kind of data the property stores.
Array<string>

Examples

Get the names of the pages associated with this router

export function myRouter_Router(request) {

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

}

path

Returns the path of the router request URL.

Description

Premium sites:

Free sites:

Syntax

get path(): Array<string>
TYPE
?
The kind of data the property stores.
Array<string>

Examples

Get the path of the router request's URL

export function myRouter_Router(request) {

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

}

prefix

Returns the router prefix of the router request URL.

Description

Premium sites:

Free sites:

Syntax

get prefix(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the prefix of the router request's URL

export function myRouter_Router(request) {

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

}

protocol

Returns the protocol of the router request URL.

Description

Premium sites:

Free sites:

Syntax

get protocol(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the protocol of the router request's URL

export function myRouter_Router(request) {

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

}

query

Returns the query fields and values of the request URL.

Description

Premium sites:

Free sites:

Syntax

get query(): Object
TYPE
?
The kind of data the property stores.
Object

Examples

Get the query of the router request's URL

export function myRouter_Router(request) {

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

referrer

Returns the referrer header from the router request.

Description

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

Syntax

get referrer(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the referrer header from the router request

export function myRouter_Router(request) {

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

}

url

Returns the full URL of the router request.

Description

Premium sites:

Free sites:

Syntax

get url(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the URL of the router request

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

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

Description

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

Syntax

get user(): WixRouterUser

Examples

Get the user from the router request

export function myRouter_Router(request) {

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

userAgent

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

Syntax

get userAgent(): string
TYPE
?
The kind of data the property stores.
string

Examples

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

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"

}