4

I am exploring lightning experience and trying to leverage aura framework. I have a button that calls an event e.force:navigateToURL. Initially it gave an error :

Action failed: c:LightningForceNavigateToURLDemo$controller$gotoURL [Cannot read property 'setParams' of undefined]

So I added aura dependency markup in the lightning component below. So the error is gone, but still the redirect doesnot happen. Am I missing anything? Any help is appreciated.. Thanks in advance.

Below is my code for quick reference:

Lightning Component:

<aura:component implements="force:appHostable">
<aura:dependency resource="markup://force:navigateToURL" type="EVENT"/>
    <div id="aura-page">
        <div class="container">
            <ui:button label="gotoURL" press="{!c.gotoURL}" />
        </div>
    </div>
</aura:component>

Client side controller:

({
    gotoURL : function(component, event, helper) {
        helper.gotoURL(component);
    }
})

Helper:

({
    gotoURL : function (component) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": "/006/o"
        });
        urlEvent.fire();
    }
})
1
  • 2
    Make sure you running in one.app container.This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only.
    – vignesh
    Mar 7, 2017 at 8:52

1 Answer 1

3

Just try to do it with directly from controller. No need to use in helper. Also try to send event to helper as params.

gotoURL : function (component) {    
    $A.get("e.force:navigateToURL").setParams({ 
       "url": "/006/o" 
    }).fire();
}
5
  • Let me know if it work @Shrey
    – Tariq
    Mar 7, 2017 at 12:06
  • I updated my code by sending event to helper. Still no luck. The button click do not redirect and no action is performed. Also the way I am trying to invoke this lightning app is : **.salesforce.com/c/myApp.app
    – Shrey
    Mar 16, 2017 at 4:43
  • @Shrey May be force:navigateToURL not directly working with application. Try to add your component using App builder and then see what happen. Use this line in your component to make available in app builder <aura:component implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    – Tariq
    Mar 16, 2017 at 9:09
  • 1
    Thanks Tarif. That answered my question. This means if we launch a lightning component / application directly from url, the lightning supported navigation methods do not work.
    – Shrey
    Mar 16, 2017 at 18:21
  • 1
    @Shrey If you are not in LEX or Salesforce1, you can just use window.location normally.
    – sfdcfox
    Mar 28, 2017 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.