The URL API tells you the addresses that the site and its pages use. Use it to link to the site's pages and to respond to the address a site visitor arrives at, so your code keeps working when the site's domain or page paths change.
With the URL API, you can:
- Retrieve the full URL of the page a site visitor is on, including its query string.
- Retrieve the site root URL, to build absolute links that work on a custom domain and on a free Wix domain.
- Retrieve the URL of a page that an installed app adds to the site, such as the Bookings checkout, without hardcoding its path.
The service doesn't parse URLs or navigate. To read part of a URL, such as its path or a query parameter, use the standard URL object. To navigate from your code, use @wix/site-service-router.
- Site root URL: The site's public base URL. On a free Wix domain it includes a path prefix, such as
https://example.wixsite.com/mysite.
- App page: A page that an app installed on the site adds to it, such as the Bookings checkout page. Its app page ID stays the same across sites, even though a Wix user can change the page's path.
- Router page: A page whose path combines a fixed prefix with a per-item suffix, such as
/News/spring-sale. Here the prefix is /News and the suffix varies per item.
- Router prefix: The fixed leading part of a router page's path.
- Popup: A page that opens over the page a visitor is already on, rather than replacing it.
To use the API, install the @wix/site-service-url package:
In a React component, resolve the service with the useService hook: