Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

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

LWC Sample Code

This example moves the user's focus to the current navigation item's home page.

1import { LightningElement } from 'lwc';
2import { focusNavigationItem } from 'lightning/platformNavigationItemApi';
3
4export default class MyComponent extends LightningElement {
5    async handleFocusNav() {
6        try {
7            await focusNavigationItem();
8            console.log('Navigation item focused successfully');
9        } catch (error) {
10            console.error('Failed to focus navigation item:', error);
11        }
12    }
13}

Aura Components 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.