Newer Version Available
EnclosingTabId Context Wire Adapter for Lightning Experience
To determine if the component is within a tab or subtab, use this context wire adapter. If a caller component isn’t using the wire adapter inside a tab or subtab, the enclosing utility tab ID is null.
LWC Sample Code
To get the ID of the enclosing tab in LWC, use the EnclosingTabId wire adapter.
This component retrieves the enclosing tab ID and closes the tab.
1import { LightningElement, wire } from 'lwc';
2import { EnclosingTabId, closeTab } from 'lightning/platformWorkspaceApi';
3
4export class CloseEnclosingTabExample extends LightningElement {
5 @wire(EnclosingTabId) enclosingTabId;
6
7 handleClick() {
8 if (this.enclosingTabId) {
9 return;
10 }
11 closeTab(this.enclosingTabId);
12 }
13}For another example that uses the EnclosingTabId wire adapter, see openSubtab().
To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.
Response
This method returns a promise that, upon success, resolves to the tabId of the enclosing tab, if within a tab, or false if not within a tab.