Newer Version Available

This content describes an older version of this product. View Latest

getSelectedNavigationItem() for Lightning Experience

Returns information about the selected navigation item. This method works only in Lightning console apps.

Arguments

None

Sample Code

This component has a button that, when pressed, returns information about the selected navigation item.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global">
2    <lightning:navigationItemAPI aura:id="navigationItemAPI"/>
3    <lightning:button label="Get selected navigation item" onclick="{!c.getSelectedNavigationItem}"/>
4</aura:component>

Controller code:

1({
2    getSelectedNavigationItem : function(component, event, helper) {
3        var navigationItemAPI = component.find("navigationItemAPI");
4        navigationItemAPI.getSelectedNavigationItem().then(function(response) {
5            console.log(response);
6        })
7        .catch(function(error) {
8            console.log(error);
9        });
10    }
11})

Response

This method returns a promise that, upon success, resolves to a navigationItemInfo object. The promise is rejected on error.

The navigationItemInfo object has the following fields.
Name Type Description
label string The navigation item’s label, such as Account or Case.
developerName string The navigation item’s developer name that uniquely identifies the item. For example, Salesforce_Account or Your_VF_Page_Name.
selected boolean True if the tab is currently selected, false otherwise.
pageReference object The representation of the current page. The object returns information such as: page type (for example standard__objectPage or standard__navItemPage), object API name, and state information for the page.
Here’s the structure of a navigationItemInfo object.
1{
2      developerName : string,
3      label : string,
4      pageReference: object,
5      selected : boolean
6}