+ Start a Discussion
Siva NalamSiva Nalam 

How to give page reference to this (Expenses) tab in lightning application? Its a custom tab built on standard Opportunity object along with other standard tabs - Details, Activity and Chatter. URL is not changing when I navigate between the tabs.

User-added image
Best Answer chosen by Siva Nalam
SandhyaSandhya (Salesforce Developers) 
Hi,

Below is the sample code for the same.
 
({
    init : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Sets the route to Lightning Page
        var pageReference = {
            type: 'standard__navItemPage',
            attributes: {
                ApiName: 'Address'
            }
        };
        cmp.set("v.pageReference", pageReference);
        // Set the URL on the link or use the default if there's an error
        var defaultUrl = "#";
        navService.generateUrl(pageReference)
            .then($A.getCallback(function(url) {
                cmp.set("v.url", url ? url : defaultUrl);
            }), $A.getCallback(function(error) {
                cmp.set("v.url", defaultUrl);
            }));
    },
    handleClick: function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Uses the pageReference definition in the init handler
        var pageReference = cmp.get("v.pageReference");
        event.preventDefault();
        navService.navigate(pageReference);
    }
})

https://salesforce.stackexchange.com/questions/230745/lightning-navigation-api-pagereference-to-lightning-page-not-working
 
   Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya

 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Below is the sample code for the same.
 
({
    init : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Sets the route to Lightning Page
        var pageReference = {
            type: 'standard__navItemPage',
            attributes: {
                ApiName: 'Address'
            }
        };
        cmp.set("v.pageReference", pageReference);
        // Set the URL on the link or use the default if there's an error
        var defaultUrl = "#";
        navService.generateUrl(pageReference)
            .then($A.getCallback(function(url) {
                cmp.set("v.url", url ? url : defaultUrl);
            }), $A.getCallback(function(error) {
                cmp.set("v.url", defaultUrl);
            }));
    },
    handleClick: function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Uses the pageReference definition in the init handler
        var pageReference = cmp.get("v.pageReference");
        event.preventDefault();
        navService.navigate(pageReference);
    }
})

https://salesforce.stackexchange.com/questions/230745/lightning-navigation-api-pagereference-to-lightning-page-not-working
 
   Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya

 
This was selected as the best answer
Siva NalamSiva Nalam
Thank you Sandhya, it worked.
Rohan SahuRohan Sahu

Hey @SivaNalam

I created a similar custom tab("TestTab") on opportunity standard pages and place an LWC component inside it.
I want to navigate to the TestTab from ex: "Details tab"

I am not able to navigate, can you give me direction how you were able to achieve that?