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 Aura component has a button that, when pressed, sets the specified ID as the selected navigation item.
Component code:
<aura:component implements="flexipage:availableForAllPageTypes" description="My Lightning Component">
<lightning:navigationItemAPI aura:id="navigationItemAPI" />
<lightning:button label="Set Navigation Item" onclick="{! c.setSelectedNavigationItem }" />
</aura:component>
Controller code:
({
setSelectedNavigationItem : function(component, event, helper) {
var navigationItemAPI = component.find("navigationItemAPI");
navigationItemAPI.setSelectedNavigationItem({
"developerName": "standard-Account"
}).then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
})
Response
This method returns a promise that, upon success, resolves to true.