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
venkat bojjavenkat bojja 

Navigate one component to another component in lightning

Hi Team,
Just I created two components. My requirement is need to navigate one component to another component when i click on my image.
But i am getting some error like...This page has an error. You might just need to refresh it.
Action failed: c:Component1$controller$click [Cannot read property 'setParams' of undefined].
            
                Please help me on this... Thanks in advance...

Component1:

<ul class="slds-list--horizontal slds-has-dividers_around-space" onclick="{!c.click}">

  <lightning:layout >
            <lightning:layoutItem size="3" padding="around-small">
                 <div class="img " >
                    <img  style="height: 100px;" src="/resource/Images/Assets/1.png"  />   
                  <h1>TEXT1</h1>
                </div> 
            </lightning:layoutItem>
            <lightning:layoutItem size="3" padding="around-small">
                <div class="img1" >
                    <img style="height: 100px;" src="/resource/Images/Assets/2.png"  />  
                   <h1>TEXT2</h1>
                </div> 
            </lightning:layoutItem>
            <lightning:layoutItem size="3" padding="around-small">
               <div class="img2" ><img style="height: 100px;" src="/resource/Images/Assets/3.png" align="middle" />      
                <h1>TEXT3</h1>
                </div>
            </lightning:layoutItem>
            <lightning:layoutItem size="3" padding="around-small">
                <div class="img3"  style="text-align: left">
                    <img style="height: 100px;" src="/resource/Images/Assets/4.png"/>  
                    <h1>TEXT4</h1>
                </div>
            </lightning:layoutItem>
        </lightning:layout>
              


</ul>   

Controller.Js


click:function(component,event,helper){        

       
       var evt = $A.get("e.force:navigateToComponent");
        evt.setParams({
            componentDef : "c:Component2",
        
            });
        
      
        evt.fire();
    }
    
    Thanks
    Venkat
Best Answer chosen by venkat bojja
MagulanDuraipandianMagulanDuraipandian
Check the code in the below link. It worked for me

​https://www.infallibletechie.com/2018/03/lightning-component-navigation-in.html

All Answers

MagulanDuraipandianMagulanDuraipandian
Check the code in the below link. It worked for me

​https://www.infallibletechie.com/2018/03/lightning-component-navigation-in.html
This was selected as the best answer
venkat bojjavenkat bojja
Hi Magulan D,
                      Thanks for your help. It is working fine.

Thanks
Venkat