Newer Version Available

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

focusNavigationItem() for Lightning Experience

Focuses on the selected navigation object and opens the object's home page. Typically, standard and custom objects open the object's list view. If split view is open, focus remains on the selected navigation object. This method works only in Lightning console apps.
Keep these things in mind when working with this method.
  • If a tab is already open for the navigation item, the focus is set on the tab.
  • If split view is open, the focus is set on the navigation tab.
  • If split view is collapsed, the navigation item’s tab is opened and focus is set on the tab.

Arguments

None

Sample Code

This component has a button that, when pressed, focuses on the navigation item and opens the navigation item’s home page. For most objects, the home page is the object’s list view.

Component code:

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

Controller code:

1({
2    focusNavigationItem : function(component, event, helper) {
3        var navigationItemAPI = component.find("navigationItemAPI");
4        navigationItemAPI.focusNavigationItem().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 true. The promise is rejected on error.