• Ferran Garcia Pallarés
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I’ve tried different ways of getting a redirection done following a bunch of tutorials and SF documentation (almost useless for me):
http://www.soliantconsulting.com/blog/2016/04/embed-a-lightning-component-in-a-visualforce-page
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToURL.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_example.htm
 
Also tried using window.location directly, but that resulted in errors.
Code below.
 
Any help is appreciated,
Francisco
 
VF page:
<apex:includeScriptvalue="/lightning/lightning.out.js"/>
.
.
.
<script>
functioncreate_object(){
$Lightning.use("c:LightningApplication", function() {                        $Lightning.createComponent("c:LightningComponent",
             {  },
             "",
             function(component) {}
             );
       });
}
                          
create_object();
</script>
 
LightningApplication.app
<aura:application access="global" extends="ltng:outApp">
       <c:LightningComponent />
<aura:dependency resource="c:LightningComponent"/>
</aura:application>
 
LightningComponent.cmp
<aura:component access="global">
<aura:registerEvent name="Event" type="c:LightningEvent"/>
       <ui:button
label="Redireccion"
               press="{!c.test}" >
</ui:button>
</aura:component>
 
LightningComponentController.js
({
       test : function(component, event, helper) {
var redirect = $A.get("e.force:navigateToURL");
             if (redirect){
redirect.setParams({
                "url": "https://www.google.com"
            });
                    redirect.fire();
        } else {
                    component.find("button1").set("v.label",'Nothing happened');
        }
       }
})
 
LightningEvent.evt
<aura:event type="COMPONENT" description="Event template" >
<aura:attribute name="url" type="String"/>
</aura:event>