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

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

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

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

Code to get URL in the javascript file,

define([
   'mage/url'
], function (urlBuilder) {
  var customLink = urlBuilder.build('customer/account/login');
  console.log(customLink);
});

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

You can pass any URL path inside the build('') method of the 'mage/url' object.