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
Niraj Singh 28Niraj Singh 28 

How can i redirect to another component using anchor tag

I have needed to redirect on another component after clicking on an image. 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Niraj,

Greetings to you!

You can use lightning:navigation with the anchor tag.

Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:isUrlAddressable" access="global" >
    
    <aura:attribute name="url" type="String"/>
    <aura:attribute name="pageReference" type="Object"/>
    
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    
    <lightning:navigation aura:id="navService"/>
    <a onclick="{!c.handleClick}">Link</a>
</aura:component>

Controller:
({
    init : function(cmp, event, helper) {
    },
    
    handleClick : function(component, event, helper) {
        var navService = component.find("navService");
        var pageReference = {
            "type": "standard__component",
            "attributes": {
                "componentName": "c__Insert_Task1"  // c__YourComponentName
            }
        }
        
        navService.navigate(pageReference);
    }   
})

Don't forget to implement lightning:isUrlAddressable in both the component.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Deepali KulshresthaDeepali Kulshrestha
Hi Niraj,
Please go through the link below.
https://salesforce.stackexchange.com/questions/137876/anchor-tag-equivalent-in-lightning-component

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha