Building URLs in JavaScript
In Luma the mage/url
module is used prepend an URL path with the current store base URL.
With Hyvä it is much simpler: the window.BASE_URL
variable can be used.
BASE_URL
For regular requests, use
or the template literal versionThe above is the equvalent to what the Luma urlBuilder.build()
method does.
A alternative option is to render the base URL with PHP:
There is no "better" or "worse" way to do this.
CURRENT_STORE_CODE
If you need to add the store code to the request path, for example for Ajax requests, use
Or, the non-template literal version: