This is a simple component, not sure what I am missing, this is exactly referred in the docs:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToURL.htm
Component:
<aura:component >
<aura:handler name="init" action="{!c.navigate}" value="this"/>
</aura:component>
JSController:
({
navigate : function(component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": 'https://www.google.com/maps/place/'
});
urlEvent.fire();
}
})
Error:
This page has an error. You might just need to refresh it.
Action failed: c:navigatetoURlcmp$controller$navigate [Cannot read property 'setParams' of undefined]
Failing descriptor: {c:navigatetoURlcmp$controller$navigate}
Best Answer
Did you embed this in an object app builder page or previewing through dev console.
If you are previewing through dev console force events are available only inside a one.app container.
your app is a standalone and the resulting page will be directed to lightning.force.com your force events will not work as expected.
Preview from dev console redirect me to :
As per official docs