To use the location module, import wixLocationFrontend from the wix-location-frontend module:
The setter functions in wix-location-frontend
can only be used when browser
rendering happens,
meaning you can only use them in frontend code after the page is ready.
You can use the getter functions for both server-side or browser rendering.
The URL is broken into:
For premium sites, the URL of the incoming call has the following format:
https://www.domain.com/myPrefix/myPath?myQuery=myValue
https://www.domain.com
myPrefix
myPath
myQuery=myValue
Example:
https://domain.com/animals/elephant?species=african-elephant
https://domain.com/
animals
. Only for routers and dynamic pages.elephant
species=african-elephant
For free sites, the URL of the incoming call has the following format:
https://user_name.wixsite.com/mysite/myPrefix/myPath?myQuery=myValue
https://user_name.wixsite.com/mysite
myPrefix
myPath
myQuery=myValue
Example:
https://user_name.wixsite.com/zoo/animals/elephant?species=african-elephant
https://user.wixsite.com/zoo
animals
. Only for routers and dynamic pages.elephant
species=african-elephant
Learn more about wix-location-frontend in Getting Started and on Wix Learn.
Gets the base URL of the current page.
Premium sites:
Free sites:
import wixLocationFrontend from "wix-location-frontend";
// Premium site URL: "https://www.domain.com/elephant?species=african-elephant"
// Free site URL: "https://user_name.wixsite.com/zoo/elephant?species=african-elephant"
let baseUrl = wixLocationFrontend.baseUrl;
// Premium site: "https://domain.com/"
// Free site: "https://user_name.wixsite.com/zoo/"
Gets the path of the current page's URL.
The path for a regular page is after the baseUrl
If the page is a dynamic page or router page, the prefix
appears after the base URL, before the path.
Premium sites:
Path for a regular page, without a prefix:
Path for a dynamic or router page with a prefix:
Free sites:
Path for a regular page, without a prefix:
Path for a dynamic or router page with a prefix:
import wixLocationFrontend from "wix-location-frontend";
// Premium site URL: "https://www.domain.com/elephant?species=african-elephant#desc"
// Free site URL: "https://user_name.wixsite.com/zoo/elephant?species=african-elephant#desc"
let path = wixLocationFrontend.path; // ["elephant"]
Gets the prefix of a dynamic page's or router page's URL.
Only dynamic pages and router pages have a prefix. The value of the
prefix
property for other page types is always undefined
.
Premium sites:
Free sites:
To learn more about dynamic page prefixes, see About URL Prefixes and Page Grouping of Dynamic Pages.
To learn more about router page prefixes, see About Routers.
import wixLocationFrontend from "wix-location-frontend";
// Premium site URL: "https://www.domain.com/mammals/elephant?species=african-elephant#desc"
// Free site URL: "https://user_name.wixsite.com/zoo/mammals/elephant?species=african-elephant#desc"
let prefix = wixLocationFrontend.prefix; // "mammals"
Gets the protocol of the current page's URL.
Premium sites:
Free sites:
import wixLocationFrontend from "wix-location-frontend";
// Premium site URL: "https://www.domain.com/animals/elephant?species=african-elephant#desc"
// Free site URL: "https://user_name.wixsite.com/zoo/animals/elephant?species=african-elephant#desc"
let protocol = wixLocationFrontend.protocol; // "https"
Gets an object that represents the query segment of the current page's URL.
Premium sites:
Free sites:
import wixLocationFrontend from "wix-location-frontend";
// Premium site URL: "https://www.domain.com/animals/elephant?species=african-elephant#desc"
// Free site URL: "https://user_name.wixsite.com/zoo/animals/elephant?species=african-elephant#desc"
let query = wixLocationFrontend.query; // {"species": "african-elephant"}
Gets an object used to manage the query segment of the current page's URL.
import wixLocationFrontend from "wix-location-frontend";
// ...
wixLocationFrontend.queryParams.add({
key2: "value2new",
key3: "value3",
});
// URL before addition:
// www.mysite.com/page?key1=value1&key2=value2
// URL will look like:
// www.mysite.com/page?key1=value1&key2=value2new&key3=value3
Gets the full URL of the current page.
Premium sites:
Free sites:
import wixLocationFrontend from "wix-location-frontend";
// ...
let url = wixLocationFrontend.url;
// Premium site: "https://www.domain.com/animals/elephant?species=african-elephant#desc"
// Free site: "https://user_name.wixsite.com/zoo/animals/elephant?species=african-elephant#desc"