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
.
export function myRouter_Router(request) {
let formFactor = request.formFactor; // "desktop"
}
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', ...)
).