+ Start a Discussion
sumit dsumit d 

Aura navigation to record not working

Hi All,
          I have a Aura component in which i want to redirect it to the record in another window. but its not working
My component is given below:- 

<aura:component implements="force:hasRecordId" access="global">
    <aura:attribute name="obName" type="String" />
    <aura:attribute name="fieldName" type="String" />
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <aura:attribute name="pageReference" type="Object"/>
    <lightning:navigation aura:id="navService"/>
    
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="COMPACT"
                      targetRecord="{!v.record}"
                      targetFields="{!v.simpleRecord}"
                      targetError="{!v.recordError}"  />
    <!-- Display a header with details about the record -->
    <div class="slds-page-header" role="banner">
        <tr>
            <td>
                <p class="slds-text-heading--label"><a onclick="{!c.redirectDetail}">
                    <lightning:formattedText value="{!v.simpleRecord.Name}" />

                    </a></p>
            </td>
            
        </tr>
    </div>
    
</aura:component>
****************************************************************
Js File
({
    doInit : function(component, event, helper) {
        var sobject = component.get('v.record');
        var fieldName = component.get('v.fieldName');
        var formatText = component.find('fielddata');
        console.log('----sobject-----------');
         console.log(sobject);
        formatText.set("v.value",sobject[fieldName]);
    },
    
    redirectDetail : function(component, event, helper) {
        //Redirect to detail page on success
        var navService = component.find('navService');
    
        var pageReference = {
            type: 'standard__recordPage',
            attributes: {
                "recordId": component.get("v.recordId"),
                "objectApiName": component.get("v.obName"),
                "actionName": "view"
            }
        }
        //event.preventDefault();
        navService.navigate(pageReference);
    }
})
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sumit,

Refer the below links will help you resolve the issue.

https://developer.salesforce.com/docs/component-library/bundle/force:navigateToSObject/documentation
https://developer.salesforce.com/forums/?id=9062I000000IFsbQAG

If this information helps, Please mark it as best answer.

Thanks!!