Anchor Tag: <a>

Don’t hard code or dynamically generate Salesforce URLs in the href attribute of an <a> tag. Use events, such as force:navigateToSObject or force:navigateToURL, instead.

Using the href attribute of an <a> tag leads to inconsistent behavior in different apps and shouldn’t be relied on. For example, don’t use this markup to link to a record:

If you use # in the href attribute, a secondary issue occurs. The hash mark (#) is a URL fragment identifier and is often used in Web development for navigation within a page. Avoid # in the href attribute of anchor tags in Lightning components as it can cause unexpected navigation changes, especially in the Salesforce mobile app. That’s another reason not to use href.

Use the navigation service for consistent linking behavior across Lightning Experience, the Salesforce mobile app, and Experience Builder sites.

lightning:navigation Navigates to a page or component.

lightning:isUrlAddressable Enable a component to be navigated directly via a URL.

We recommend replacing these navigation events with the navigation service.

force:navigateToList Navigates to a list view.

force:navigateToObjectHome Navigates to an object home.

force:navigateToRelatedList Navigates to a related list.

force:navigateToSObject Navigates to a record.

force:navigateToURL Navigates to a URL.

As well as consistent behavior, using navigation events instead of <a> tags reduces the number of full app reloads, leading to better performance.

See Also