To view the page context, use a change-event handler in the Utility Bar component. If a user navigates to a different page, the recordId of the view is captured. The following code snippet shows a simple demonstration:
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes"
access="global">
<aura:handler name="change" value="{!v.recordId}" action="{!c.onRecordIdChange}"/>
<div>
<p>The current recordId is {!v.recordId}.</p>
</div>
</aura:component>
The controller code for the preceding component is as follows:
({
onRecordIdChange : function(component, event, helper) {
var newRecordId = component.get("v.recordId");
console.log(newRecordId);
}
})