The WixRouterRequest
object breaks the URL of the incoming router request
into different parameters for easy access.
The URL is broken into:
For premium sites, the URL of the site router request has the following format:
https://www.domain.com/myPrefix/myPath?myQuery=myValue#myHashDesc
https://www.domain.com
myPrefix
myPath
myQuery=myValue
#myHashDesc
Example:
https://domain.com/mammals/elephant?species=african-elephant#LifeSpan
https://domain.com/
mammals
elephant
species=african-elephant
#LifeSpan
For free sites, the URL of the site router request has the following format:
https://user.wixsite.com/mySite/myPrefix/myPath?myQuery=myValue#myHashDesc
https://user.wixsite.com/mySite
myPrefix
myPath
myQuery=myValue
#myHashDesc
Example:
https://user.wixsite.com/zoo/mammals/elephant?species=african-elephant#LifeSpan
https://user.wixsite.com/zoo
mammals
elephant
species=african-elephant
#LifeSpan
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
Returns the base URL of the router request.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
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.
Returns the form factor of the device used to make the router request.
Returns either desktop
or mobile
.
Returns the remote IP address of the router request.
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', ...)
).
Returns the path of the router request URL.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
Returns the router prefix of the router request URL.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
Returns the protocol of the router request URL.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
Returns the query fields and values of the request URL.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
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.
Returns the full URL of the router request.
Premium sites:
Free sites:
Note: The above URLs are for a published site. When previewing your site, you will receive the Editor URL.
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.
Returns the user-agent
header as sent from 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"
}