Introduction

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

The URL is broken into:

Premium Sites

For premium sites, the URL of the site router request has the following format: https://www.domain.com/myPrefix/myPath?myQuery=myValue#myHashDesc

  • baseUrl:     https://www.domain.com
  • prefix:        myPrefix
  • path:          myPath
  • query:        myQuery=myValue
  • hash:        #myHashDesc

Example: https://domain.com/mammals/elephant?species=african-elephant#LifeSpan

  • baseUrl:     https://domain.com/
  • prefix:        mammals
  • path:          elephant
  • query:        species=african-elephant
  • hash:        #LifeSpan

Free Sites

For free sites, the URL of the site router request has the following format: https://user.wixsite.com/mySite/myPrefix/myPath?myQuery=myValue#myHashDesc

  • baseUrl:     https://user.wixsite.com/mySite
  • prefix:        myPrefix
  • path:          myPath
  • query:        myQuery=myValue
  • hash:        #myHashDesc

Example: https://user.wixsite.com/zoo/mammals/elephant?species=african-elephant#LifeSpan

  • baseUrl:     https://user.wixsite.com/zoo
  • prefix:        mammals
  • path:          elephant
  • query:        species=african-elephant
  • hash:        #LifeSpan

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Did this help?

baseUrl


baseUrlstringRead-only

Returns the base URL of the router request.

Premium sites: Premium site baseUrl

Free sites: Free site baseUrl

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the base URL of the router request
JavaScript
Did this help?

env


envstringRead-only

Returns the current environment the router rendering process is running in.

When possible, the rendering process is split in two in order to improve performance. The first cycle in the process is initiated from backend rendering, and the second cycle is initiated from client-side rendering. Note that even when the rendering cycle is initiated from client-side rendering, router code is called, and router code always runs in the backend.

If not possible on the backend, all rendering is initiated from the client side.

The env property returns "backend" when rendering on the backend, and "browser" when rendering on the client.

Use the env property in your page's onReady() event handler to control where your code runs during the rendering process and to prevent code that causes side effects from running twice.

Note: Rendering never occurs on the backend when previewing your site.

Get the current environment the router request is running in
JavaScript
Did this help?

formFactor


formFactorstringRead-only

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

Returns either desktop or mobile.

Get the form factor of the device used to make the router request
JavaScript
Did this help?

ip


ipstringRead-only

Returns the remote IP address of the router request.

Get the IP of the router request
JavaScript
Did this help?

pages


pagesArray<string>Read-only

Returns the names of the pages associated with this router.

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

Get the names of the pages associated with this router
JavaScript
Did this help?

path


pathArray<string>Read-only

Returns the path of the router request URL.

Premium sites: Premium site path

Free sites: Free site path

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the path of the router request's URL
JavaScript
Did this help?

prefix


prefixstringRead-only

Returns the router prefix of the router request URL.

Premium sites: Premium site prefix

Free sites: Free site prefix

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the prefix of the router request's URL
JavaScript
Did this help?

protocol


protocolstringRead-only

Returns the protocol of the router request URL.

Premium sites: Premium site protocol

Free sites: Free site protocol

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the protocol of the router request's URL
JavaScript
Did this help?

query


queryQueryRead-only

Returns the query fields and values of the request URL.

Premium sites: Premium site query

Free sites: Free site query

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the query of the router request's URL
JavaScript
Did this help?

referrer


referrerstringRead-only

Returns the referrer header from the router request.

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

Get the `referrer` header from the router request
JavaScript
Did this help?

url


urlstringRead-only

Returns the full URL of the router request.

Premium sites: Premium site URL

Free sites: Free site URL

Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.

Get the URL of the router request
JavaScript
Did this help?

user


userWixRouterUserRead-only

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

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

Get the user from the router request
JavaScript
Did this help?

userAgent


userAgentstringRead-only

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

Get the `user-agent` header of the device used to make the router request
JavaScript
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" }
Did this help?