Thanks to Khoa for his explanation what I wanted to achieve is in my admin form I am calling an external url with ajax. I was using a static path so I wanted it dynamically. So here's what I have done.
My Layout XML File
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<uiComponent name="namespace_modulename_form"/>
<block class="Namespace\Modulename\Block\Adminhtml\Edit" name="edit" template="Namespace_Modulename::edit.phtml" />
</referenceContainer>
</body>
</page>
Layout Phtml File I defined the baseUrl.
<script>
require([
'mage/url'
], function(url) {
return url.setBaseUrl('<?php /* @escapeNotVerified */ echo $block->getAdminBaseUrl();?>');
})
</script>
My block file which returns the base url
<?php
namespace Namespcae\Modulename\Block\Adminhtml;
class Edit extends \Magento\Framework\View\Element\Template
{
protected $_configReader;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\DeploymentConfig\Reader $configReader
) {
$this->_configReader = $configReader;
parent::__construct($context);
}
public function getAdminBaseUrl(){
$config = $this->_configReader->load();
$adminSuffix = $config['backend']['frontName'];
return $this->getBaseUrl() . $adminSuffix . '/';
}
}
Now in my js files I can use it as.
define([
'Magento_Ui/js/form/element/abstract',
'mage/url'
], function (Abstract, url) {
'use strict';
return Abstract.extend({
url.build('namespace_module/controllername/action/');
});
});