function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Niraj Singh 28Niraj Singh 28 

lightning:navigation for custom component

How can i use <lightning:navigation> for custom component using javascript code
Khan AnasKhan Anas (Salesforce Developers) 
Hi Niraj,

Greetings to you!

lightning:navigation component is used to navigate to a given pageReference or to generate a URL from a pageReference.

Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:hasPageReference,lightning:isUrlAddressable"
               access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <lightning:navigation aura:id="navigate" />
    <lightning:button label="Lightning Navigate" onclick="{!c.navigate}"
                     variant="brand"/>
    <!-- <lightning:button label="Lightning Navigate" onclick="{!c.navigate}" 
                     variant="brand" /> -->
</aura:component>

Controller:
({
    doInit : function(component, event, helper) {
        
    },
    navigate : function(component, event, helper) {
        var nagigateLightning = component.find('navigate');
        var pageReference = {
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Account',
                actionName: 'list'
            },
            state: {
                filterName: 'MyAccounts'
            } 
        };
        nagigateLightning.navigate(pageReference);
    }
})

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/docs/component-library/bundle/lightning:navigation/documentation

https://wedgecommerce.com/lightningnavigation-lightning-component/

http://simpluslabs.com/how-to-use-lightningnavigation-to-navigate-another-component/

http://bobbuzzard.blogspot.com/2018/05/lightning-component-navigation-in.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas