1

I have 3 components namely Employee Division which will show his division details like manufacturing,accounts etc and Employee Profile which will show his Profile details and an Dashboard Component where we will have 2 buttons say division and profile.I need to load division component when Division button is pressed and similarly profile. Is there any way to load this without using window.location.href

1 Answer 1

0

You can dynamically create the lightning components on click of button and add it into the v.body of the current displayed component. Here is an example

Have the following code in your division button click:

goToDiv : function(component, event, helper){
    $A.createComponent(
                "c:EmployeeDivisionCmp",
                {
                    "aura:id": "empDivId"
                },
                function(newComp){
                    if (component.isValid()) {
                      var body = component.get("v.body");
                      body = [];
                      body.push(newComp);
                      component.set("v.body", body);
                   }
                }
            );
}

Now this should remove the current UI elements from the display and load the EmployeeDivisionCmp in the view.

Just being curious, how were you planning to redirect lightning components using window.href.location?

7
  • window.location.href ="/c/ComponentRedirectApp.app?componentName=EmployeeDivisionCmp"
    – Ganesh
    Commented Sep 12, 2016 at 7:23
  • Okay, componentName is standard variable or your custom attribute in ComponentRedirectApp? Commented Sep 12, 2016 at 7:30
  • probably it may change that's way looking for an alternate way to change it to make redirection in some other way.
    – Ganesh
    Commented Sep 12, 2016 at 8:36
  • You can try the one I mention, it works for me pretty well and its salesforce standard too. Commented Sep 12, 2016 at 9:25
  • It works fine but I cant able to hide existing component when new component is loaded.
    – Ganesh
    Commented Sep 12, 2016 at 9:42

Not the answer you're looking for? Browse other questions tagged .