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
Bharat.SharmaBharat.Sharma 

Navigate from a Lightning Component to Another

Hello, I am working on lightning component and stuck on scenario is there any way to switch one lightning component to another component when both are in different lightning pages.  
Please Help Me.
Thanks In Advance. :)
Best Answer chosen by Bharat.Sharma
sfdcMonkey.comsfdcMonkey.com
This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce app only.
 

All Answers

sfdcMonkey.comsfdcMonkey.com
Hi bharat, use e.force:navigateToComponent​ for Navigate to another component 
 
navigateToMyComponent : function(component, event, helper) {
    var evt = $A.get("e.force:navigateToComponent");
    evt.setParams({
        componentDef : "c:myComponent",
        componentAttributes: {
            contactName : component.get("v.contact.Name")
        }
    });
    evt.fire();
}

for refernece : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToComponent.htm?search_text=navigate 

Thanks, let me inform if it helps you 
Amit Singh 1Amit Singh 1
+1 Piyush,

This is what you need to Navigate from one component to another 
Bharat.SharmaBharat.Sharma

Thanks Piyush for very fast reply, I am trying the same but getting error :

[Cannot read property 'setParams' of undefined] 

Here evt variable getting undifined , i am checking in console.log(evt).

sfdcMonkey.comsfdcMonkey.com
This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce app only.
 
This was selected as the best answer
Bharat.SharmaBharat.Sharma

YES!!
Thank you Piyush for the help its working fine now !!

David Roberts 4David Roberts 4
Many thanks form me, too, Piyush. Great post!
David Roberts 4David Roberts 4
e.force:navigateToComponent is deprecated.
How do I navigate to an account page.
I'm getting a setparams error using Raj Vakati's sample at:
https://rajvakati.com/2018/05/29/navigation-in-lightning-experience-using-pagereference/

var navService = cmp.find("navigateToAccount");
        console.log('nav service: '+navService);  
        //console.log(cmp.get("v.SendMessage")); 
        var pageReference = {
            type: "standard__objectPage",
            attributes: {
                objectApiName: "Account",
                actionName: "list"
            },
            state: {}
        };
        
        
               
        console.log('navTo: '+ pageReference);
        
       
        cmp.set("v.pageReference", pageReference);
        var defaultUrl = "#";
        
        navService.generateUrl(pageReference)
        .then($A.getCallback(function(url) {
            cmp.set("v.url", url ? url : defaultUrl);
        }), $A.getCallback(function(error) {
            console.log('there was an error: '+error);
            cmp.set("v.url", defaultUrl);
        }));
        
Ankita Rustagi 26Ankita Rustagi 26
@Piyush_soni, @Bharat.sharma.. what was the resolution for evt param undefined error. Kindly share. Facing the same issue.