+ Start a Discussion
NDangNDang 

Not able to redirect to a lightning component from visualforce page in Salesforce1

I have a visuaforce page which opens from a Lightning component (not lightning app). Now, I want to redirect my user to another Lightning component from this visualforce page but not able to do so, I have used sforce.one.navigateToURL and window.location but nothing worked. Any way to achieve this?
bob_buzzardbob_buzzard
There's a navigateToComponent method for this scenario. This thread (https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Az3jIAC) covers it in detail, but here's the example:
 
navigateToRollCall : function(component, event, helper) {
    var evt = $A.get("e.force:navigateToComponent");
        evt.setParams({
            componentDef: "c:AttendanceRollCall",
            componentAttributes: {
                programId: component.get("v.program.Id")
            }
        });
    evt.fire();    
}

 
Charlotte GibsonCharlotte Gibson
Hi Guys!

I'm having a similar issue navigating to a Lightning Component from a VF page as you, NDang - did you have any luck with this one?

Bob, in relation to the above question - do you know if there's a way to access the navigateToComponent functionality FROM a VF page? I'm able to scoot between lightning components just fine, and can get to a VF page from a Lightning Component, but am having trouble accessing a lightning component from a link in a visualforce page - is it even possible? I'm trying to link up a Google Maps page using the "find nearby warehouse" example in the Winter 15 App Developer Guide (Chapter 11 of this guide (https://astuet.files.wordpress.com/2014/03/salesforce1-app-developer-guide.pdf)) to a custom lightning component that I've created, but I can't find any documentation about linking a VF page to a lightning component - I need to pass a couple of component attributes into it as well. Do you have any idea if it's even possible?

Cheers,
Charlotte
Anitha J J 2Anitha J J 2
Hi Charlotte,

You have mentioned that you are able to navigate from one lightning componenet to another componenet ...How??Could you please explain..I'm new to Lightning.

Regards,
Anitha
bob_buzzardbob_buzzard
The navigateToComponent has now been removed - apparently it should never have been made available externally. As far as I am aware there isn't currently a replacement.
David Roberts 4David Roberts 4
What do you men - removed? I'm using it now (2018).
Although I do have an issue - the link works fine but always to an old version of the component. I can't figure out why. Hoping support can tell me...
Yogesh.AroraYogesh.Arora
There isn't any documented way of doing that, but I was able to do so using a hack.

The Salesforce Lightning URL is something like "/one/one.app#_______" . The blank contains some encoded value in the URL. The encoded value is nothing but the details of the Component/Page in Base64 encoded form.

Use the below code in Javascript in Visualforce to navigate to Lightning Components-
<script>
var compDefinition = { 
    "componentDef" : "c:NewContact", 
    "attributes" :{ 
          "recordTypeId" : "012xxxxxxxxxxxx",
          "testAttribute" : "attribute value"
     } 
    };
// Base64 encode the compDefinition JS object
var encodedCompDef = btoa(JSON.stringify(compDefinition));
window.parent.location = "/one/one.app#"+encodedCompDef;
</script>