How to get Custom, Base Url in JS file Magento 2?

You can get the custom or base URL of store in javascript(JS) file for frontend area using ‘mage/url’ widgets.

You have to pass ‘mage/url’ widget as a dependency in a define([]) or require([]) function of the javascript file.

You can fetch Custom Base Url for Backend area using Backend Base Url in JS file

Code to get URL in the javascript file,

Using the above code snippet, You can fetch the store login page URL.

You can pass any url path inside the build(”) method of ‘mage/url’ object.