Activity Forums Salesforce® Discussions How can we navigate from one component to another component ?

  • Nikita

    Member
    September 25, 2019 at 11:16 am

    Hi Hariom,

    Please refer the below example.

    Here I have got two components named, Main.cmp and C1.cmp. You can navigate from Main.cmp to C1.cmp using the below snippets.

    main.cmp

    <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
        
        <ui:button label="Navigate to C1" press="{!c.Navigate}"/>
        
        {!v.body}
    	
    </aura:component>

    MainController.js

    ({
    	Navigate : function(component, event, helper) {
             $A.createComponent(
                "c:C1",
                {
                     
                },
                function(newCmp){
                    if (component.isValid()) {
                        var body = component.get("v.body");
                        body.push(newCmp);
                        component.set("v.body", body);
                    }
                }
            );	        
    		
    	}
    })

    C1.cmp

    <aura:component >
        
        Component C1 Successfully Loaded ! ! !
    	
    </aura:component>

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos