Get Backend Base Url in JS file Magento 2?

You can get base URL of the backend/admin panel in javascript(JS) file to fetch Custom URL of a site to call ajax request in backend area.

‘mage/url’ widget is not used to fetch backend base URL in Magento 2.

You need to create a template file using layout XML and define the base URL of backend under the template file. Continue reading “Get Backend Base Url in JS file Magento 2?”

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. Continue reading “How to get Custom, Base Url in JS file Magento 2?”

Get Base Url in Model or Plugin file Magento 2.

You can get the base URL of the store in the controller file using Store Manager Interface.

To Retrieve the Base URL of the current store, You need to instantiate constructor in your controller file,

Check below code snippet for getting base URL, Continue reading “Get Base Url in Model or Plugin file Magento 2.”