closeTab() for Lightning Experience
Arguments
The method provides the same argument for both Aura Components and Lightning Web Components (LWC).
| Name | Type | Description |
|---|---|---|
| tabId | string | ID of the workspace tab or subtab to close. |
LWC Sample Code
This component checks if it’s in a Lightning console app using the isConsoleNavigation wire adapter. When the getFocusedTabInfo() resolves successfully, it returns the tabInfo object. The const { tabId } syntax destructures the tabInfo object and binds the tabInfo.tabId value on the tabId variable. closeTab() uses this tabId value to close the tab.
This example shows the workspaceAPICloseTab component in the lwc-recipes repo.
To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.
Aura Components Sample Code
This component has a button that, when pressed, closes the currently focused tab.
Component code:
Controller code:
Response
This method returns a promise that resolves to true if successful. The promise is rejected on error.