Newer Version Available
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:
1<aura:component implements="forceCommunity:availableForAllPageTypes">
2 <aura:attribute name="recordId" type="String" default="500xx000000YkvU" />
3 <aura:attribute name="routeInput" type="Map"/>
4 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
5 <forceCommunity:routeLink id="myCaseId" class="caseClass" title="My Case Tooltip" label="My Case Link Text" routeInput="{!v.routeInput}" onClick="{!c.onClick}"/>
6</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.
1({
2 doInit : function(component, event, helper) {
3 component.set('v.routeInput', {recordId: component.get('v.recordId')});
4 },
5
6 onClick : function(component, event, helper) {
7 var navEvt = $A.get("e.force:navigateToSObject");
8 navEvt.setParams({
9 "recordId": component.get('v.recordId')
10 });
11 navEvt.fire();
12 }
13})The previous example renders the following anchor tag:
1<a class="caseClass" href="/myCommunity/s/case/500xx000000YkvU/mycase"
2 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. |