1

I have created a lightning component onclick button call a js function. Js function is there.

callAuthComponent : function(component, event, helper){

  console.log('call......');

    var evt = $A.get("e.force:navigateToComponent"); 
    evt.setParams({
        componentDef:"c:getAuthComponent",
    });
    evt.fire();
 }

But get the following error:

This page has an error. You might just need to refresh it. Action failed: c:LinkedinSalesforce$controller$callAuthComponent [Cannot read property 'setParams' of undefined] Failing descriptor: {c:LinkedinSalesforce$controller$callAuthComponent}

Why do I get this error? How can I fix it?

1
  • 1
    You've tagged your question salesforce1-app. Are you experiencing this issue in a component used in Salesforce mobile? If no, can you edit your question to specify where you are surfacing this component?
    – David Reed
    May 7, 2019 at 11:41

1 Answer 1

0

Try using lightning:navigation. As per the documentation examples here, you can setup your PageReference like this (note this PageReference is for navigating to the Account home tab):

var navService = cmp.find("navService");

// Sets the route to /lightning/o/Account/home
var pageReference = {
    type: 'standard__objectPage',
    attributes: {
        objectApiName: 'Account',
        actionName: 'home'
    }
};
cmp.set("v.pageReference", pageReference);

Once you've setup your PageReference specifically for you lightning component, using standard__component as the type to point to your custom component (see PageReference - Lightning Component Type, you can use the following to navigate to it:

// Get your navService library component
let navService = cmp.find("navService");

// Use navService to setup the right PageReference object
const pageReference = cmp.get("v.pageReference");

// Actually navigate to your component
navService.navigate(pageReference);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .