Newer Version Available

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

setSelectedNavigationItem() for Lightning Experience

Sets the selected navigation item to a specific ID. This method works only in Lightning console apps.

Arguments

Name Type Description
developerName string The ID of the navigation item.

Sample Code

This component has a button that, when pressed, sets the specified ID as the selected navigation item.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" description="My Lightning Component">
2    <lightning:navigationItemAPI aura:id="navigationItemAPI" />
3    <lightning:button label="Set Navigation Item" onclick="{! c.setSelectedNavigationItem }" />
4</aura:component>

Controller code:

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

Response

This method returns a promise that, upon success, resolves to true.