forceCommunity:routeLink

Sets an HTML anchor tag with an href attribute that’s automatically generated from the provided record ID. Use it to improve SEO link equity in template-based communities.

Because the href attribute is automatically generated from the provided record ID, forceCommunity:routeLink is only suitable for creating internal links to recordId-based pages in your community, such as the Article Detail or the Case Detail pages.

Internal links help establish an SEO-friendly site hierarchy and spread link equity (or link juice) to your community’s pages.

Here's an example of a forceCommunity:routeLink component:

<aura:component implements="forceCommunity:availableForAllPageTypes">
    <aura:attribute name="recordId" type="String" default="500xx000000YkvU" />
    <aura:attribute name="routeInput" type="Map"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <forceCommunity:routeLink id="myCaseId" class="caseClass" title="My Case Tooltip" label="My Case Link Text" routeInput="{!v.routeInput}" onClick="{!c.onClick}"/>
</aura:component>
        

To create the link, the client-side controller sets the record ID on the routeInput attribute during initialization. Clicking the link enables you to navigate to the record page.

({
    doInit : function(component, event, helper) {
    component.set('v.routeInput', {recordId: component.get('v.recordId')});
    },

    onClick : function(component, event, helper) {
           var navEvt = $A.get("e.force:navigateToSObject");
           navEvt.setParams({
             "recordId": component.get('v.recordId')
           });
           navEvt.fire();
   }
})
        

The previous example renders the following anchor tag:

<a class="caseClass" href="/myCommunity/s/case/500xx000000YkvU/mycase" 
   id="myCaseId" title="My Case Tooltip">My Case Link Text</a>

Attributes

Attribute Name Attribute Type Description Required?
body Component[] The body of the component. In markup, this is everything in the body of the tag.
class String A CSS class for the anchor tag.
id String The ID of the anchor tag.
label String The text displayed in the link.
onClick Action Action to trigger when the anchor is clicked.
routeInput HashMap The map of dynamic parameters that create the link. Only recordId-based routes are supported. Yes
title String The text to display for the link tooltip.