While testing different ways to provide clickable links to users, I realized that the standard documented approach doesn't seem to work and while attempting to customize a component to do the same, the onclick event did not seem to trigger my navigation method.

Example Custom Clickable link:

<div onclick="{!c.handleClick}" name="{!v.knowledgeRecord.Title}">{!v.knowledgeRecord.Title}</div>

The onclick event does not seem to work. My component is on the latest api version(44) Locker service does not seem to allow this based on past posts:

If i check the documentation on anchor tags in lightning ( Example Using Navigation Event) from the lightning developer Development guide, the suggested approach would seem to be:

<a onclick="{!c.handleClick}">{!v.knowledgeRecord.Title}</a>

Again, this method does not seem to trigger my navigation method, eventhoug the doc states:

Use Navigation Events Use one of the navigation events for consistent behavior across Lightning Experience, Salesforce app, and Lightning communities.

However, If I use a lightning:formattedUrl component, I am able to specify a value, label and so on, and onclick it seems to redirect accordingly,

<lightning:formattedUrl label="{!v.knowledgeRecord.Title}" 
                                           target="_blank" value="{! $Site.siteUrlPrefix + '/article/' + v.knowledgeRecord.Id}" />

Is the later the best approach? or am I doing something wrong when attempting to use the anchor tag (eventhough it is literally copy pasted from the documetnation).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.