+ Start a Discussion
Amit VaidyaAmit Vaidya 

force:navigateToURL

Hi Everyone,
 
//Component: LightningNavigate
<aura:component implements="force:appHostable">
    <div id="aura-page">
        <div class="container">
            <ui:button label="gotoURL" press="{!c.gotoURL}" />
        </div>
        <div class="container">
            <ui:button label="navigate" press="{!c.navigate}" />
        </div>
    </div>
</aura:component>

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

//Helper
({
    gotoURL : function (component, event) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": "/006/o"
        });
        urlEvent.fire();
    },
    navigate : function(component,event) {
        var address = '/Salesforce.com+Inc/@37.793779,-122.39448,17z/';
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": 'https://www.google.com/maps/place/' + address
        });
        urlEvent.fire();
    }
})

//App
<aura:application >
    <c:LightningNavigate />
</aura:application>

While running above code, I am getting following issue:

Something has gone wrong. Action failed: c$LightningNavigate$controller$gotoURL [TypeError: Cannot read property 'setParams' of undefined] Failing descriptor: {c$LightningNavigate$controller$gotoURL}. Please try again.

Can someone please help me to resolve it?

Thanks,
Amit
Best Answer chosen by Amit Vaidya
sharathchandra thukkanisharathchandra thukkani
and this only works in salesforce 1 not in the lightning.

All Answers

sharathchandra thukkanisharathchandra thukkani
Amit bhai tum controller se helper method gotoURL ko event pass nayi kara. meaning change the controller code to below

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

try this and check.
sharathchandra thukkanisharathchandra thukkani
and this only works in salesforce 1 not in the lightning.
This was selected as the best answer
sharathchandra thukkanisharathchandra thukkani
force:navigateToURL
Navigates to the specified URL.
Relative and absolute URLs are supported. Relative URLs are relative to the Salesforce1 mobile browser app domain, and retain navigation history. External URLs open in a separate browser window. It wont work in lightning Experience on desktop
Amit VaidyaAmit Vaidya
Sharath, I tried with your updated controller above. It still giving same issue in Lightning. As per Lightning documentation, coming to know that it's supported in Salesforce1 and Lightning Experience only. Please see below notes:

"This event is handled by the one.app container. It’s supported in Lightning Experience and Salesforce1 only. If used outside of Lightning Experience or Salesforce1, this event won’t be handled automatically. To use this event outside of one.app, create and wire up an event handler of your own."
sharathchandra thukkanisharathchandra thukkani
you are right here the trick to extecute this component is you need to use this component either in opportunity record page or home page. But if you using this lightning component in lightning app you will get the error which you posted.

So use this component either in the salesforce 1 tab/ Opprotunity record page/ home page.

force:navigateToURL works only if the url has /one/one.app doamin.
sharathchandra thukkanisharathchandra thukkani
you should not use this lightning component in the lightning app.
guna Sevugapperumal 9guna Sevugapperumal 9
I am getting the error "Something has gone wrong. $A.getDefinition. Please try again" when trying to navigate to an Lightning page built using App builder. Anyone help me understand why the url is not acceptable. But it works fine when i use the relative url ( commented line)
 
({
    gotoURL : function (component) {
        var urlEvent = $A.get("e.force:navigateToURL");
        //urlEvent.setParams({"url": "/006/o"});  // this works great
       
urlEvent.setParams({"url" : "https://agn-allergan--coe.lightning.force.com/one/one.app#eyJjb21wb25lbnREZWYiOiJvbmU6ZmxleGlwYWdlIiwiYXR0cmlidXRlcyI6eyJ2YWx1ZXMiOnsiZmxleGlQYWdlRGV2ZWxvcGVyTmFtZSI6Iktub3dsZWRnZV9DZW50ZXIiLCJsYWJlbCI6Iktub3dsZWRnZSBDZW50ZXIiLCJpY29uVXJsIjoiaHR0cHM6Ly9hZ24tYWxsZXJnYW4tLUNPRS5jczYzLm15LnNhbGVzZm9yY2UuY29tL2ltZy9pY29uL3Q0djM1L2N1c3RvbS9jdXN0b200Nl8xMjAucG5nIiwiaWNvbkNvbG9yIjoiNjdhNWU3In19LCJ0IjoxNDgzNTU4MzAzNzU0fQ%3D%3D"});  // This one gives error.
 
        urlEvent.fire();
    },
    navigate : function(component) {
        var address = '/Salesforce.com+Inc/@37.793779,-122.39448,17z/';
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": 'https://www.google.com/maps/place/' + address
        });
        urlEvent.fire();
    }
})
Sergio López CalvoSergio López Calvo
Hi, 

I´m affected by this problem,  "Something has gone wrong. $A.getDefinition. Please try again." , no body knows about, I need help¡¡

Please, if anybody knows something about, response me.

Thanks...