Why not use href=”/id” or href=”#/sObject/id/view” in Lightning?

Salesforce.com offically discourages Lightning developers to use href="/id" links in Lightning components and recommends complicated solutions as described here Locker-Service safe passing of data from <a> and <lightning:xyz> to controller.

I also found no official document explaining how and when to use the internal Lightning pseudo URLs (e.g. #/sObject//view).

Besides its complexity a solution using onlick and a JS event handler has another drawback. It disables the users option to Keyboard-click (CMD, Strg, Alt) a link to open it in a new tab.

So my question is: Why is using not allowed? And where? Are there places where I can safely use it?

Answer

In LEX, salesforce uses <a> tags with an href attribute to navigate to records.

Although rather than using href="/<id>", it is href="#/sObject/<id>/view"

enter image description here

I personally can’t say for sure whether or not the way the LEX app handles url fragments will be subject to change, or whether developers can safely use this pattern directly for controlling navigation.

Of course, if your components are going to be used in your own lightning application, you would have full control of URL-Centric Navigation and could use <a> tags freely.


Update: Summer ’18

There is now a New URL Format for Lightning Experience and the Salesforce Mobile App

Attribution
Source : Link , Question Author : Robert Sösemann , Answer Author : martin

Leave a Comment