function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VSK98VSK98 

Getting Error when redirect to another lightning

Hello All,

I have tried to redirect to another lightning page when clicking on the button but I have encountered the below error.
This page has an error. You might just need to refresh it.
Action failed: c:L_Redirect_to_Otherpage$controller$handleClick [Cannot read property 'setParams' of undefined]
Failing descriptor: {c:L_Redirect_to_Otherpage$controller$handleClick}

Snippet below.

Component:
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	
    <aura:attribute name="url" type="String" />
    
    <p><a onclick="{!c.handleClick}">link to record</a></p>

</aura:component>

JS Controller:
 
({
    handleClick: function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "url": "http:www.google.com"
        });
        navEvt.fire();
    }
})

Please help me where I did a mistake.

Regards,
VSK98

 
VSK98VSK98
HI All,

I have replaced with 
var navEvt = $A.get("e.force:navigateToURL");
in JS Controller but still an issue persists


Regards,
VSK98
mukesh guptamukesh gupta
Hi,

Please use my code in JS Controller:-
 
({
    handleClick: function (component, event, helper) {
       
          var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "url": "http:www.google.com"
    });

    urlEvent.fire();
    }
})
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
 
@@@we@@@@@@we@@@
var navEvt = $A.get("e.force:navigateToURL");

 navEvt .setParams({
    "url": "http:www.google.com"
 });

 navEvt .fire();
https://webkul.com/blog/navigating-within-lightning-components/

Kindly mark my solution as the best answer if it helps you.
 
Kuldeep Singh 102Kuldeep Singh 102
Hi VSK98,

  var navEvt = $A.get("e.force:navigateToSObject");

"navigateTo___", these kind of events only works in Salesforce1 mobile app.

Instead, you can use below code for navigating to another url.
 

var idx = event.target.id;
 var url = '/one/one.app?#/sObject/'+ idx + '/view';
 window.open(url,'_self');

Kindly mark my solution as the best answer if it helps you.

Regards,
Kuldeep Singh