It seems that for now there is no equivalent to Site.BaseUrl. So I'm going to share what I've used to circumvent this:
On the component.cmp:
<aura:attribute name="baseUrl" type="String" default=""></aura:attribute>
<aura:attribute name="theme_ui" type="String" default=""></aura:attribute>
On helper.js:
getBaseUrl : function (component) {
var action = component.get('c.getBaseUrl')
action.setCallback(this, function (response) {
var state = response.getState()
if (component.isValid() && state === 'SUCCESS') {
var result = response.getReturnValue()
component.set('v.baseUrl', result)
}
})
$A.enqueueAction(action)
},
getUIDisplayed : function (component) {
var action = component.get('c.getUIThemeDescription')
action.setCallback(this, function (response) {
var state = response.getState()
if (component.isValid() && state === 'SUCCESS') {
var result = response.getReturnValue()
component.set('v.theme_ui', result)
}
})
$A.enqueueAction(action)
},
On the server-side:
@AuraEnabled
public static String getBaseUrl () {
if (Network.getNetworkId() != null) {
return [SELECT Id, UrlPathPrefix FROM Network WHERE Id = :Network.getNetworkId()].UrlPathPrefix;
}
return '';
}
@AuraEnabled
public static String getUIThemeDescription() {
return UserInfo.getUiThemeDisplayed();
}
And where I need to make the redirect, I've used this:
if (component.get('v.theme_ui') === 'Theme3') {
// salesforce classic
window.location.href = component.get('v.baseUrl') + '/' + result
} else {
// lightning experience
sforce.one.navigateToSObject(result)
}
@AuraEnabled
Apex method that returns data from the Site class. But worth checking early though that theSite
class works in that context.