[SalesForce] How to use e:force:navigateToUrl in lightning salesforce

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();
    }
})

Best Answer

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();
}
Related Topic