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}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 :
https://namespace-dev-ed.lightning.force.com/
As per official docs
This event is handled by the one.app container. It’s supported in
Lightning Experience, Salesforce1, and Lightning communities.
Method 2
add the below dependency in the component
<aura:dependency resource="markup://force:navigateToURL" type="EVENT"/>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0