Use Page Context in the Utility Bar API

In both Lightning console apps and standard navigation apps, utilities can respond to the context of the current page. For a Lightning web component, use the CurrentPageReference wire adapter. For an Aura component, specify implements="force:hasRecordId" to access the recordId of the record a user is viewing.

The CurrentPageReference wire adapter provides the page reference that describes the current page.

The component displays the record ID when the utility bar is loaded on a record page.

For more information about working with the page reference, see the Lightning Web Components Developer Guide.

This simple component implements force:hasRecordId and listens for changes to the record being viewed. When this component is added to a utility bar, it displays the recordId of the record currently being viewed.

The component’s controller listens for changes to the recordId, and prints the new recordId to the developer console upon a change.

This image shows what the component looks like in the utility bar of a Lightning console app.

A utility bar component that displays the current recordId.