New Lightning Navigation APIs for Lightning Components

With the lightning:isUrlAddressable interface, you now control which Lightning components can be opened programmatically. You can also now easily capture URL parameters using the v.pageReference attribute and use the parameter values in your component. With the lightning:navigation component, define a pageReference object for navigating to a custom component that implements lightning:isUrlAddressable and set any attributes the component allows.

Where: This change applies to orgs with Lightning components in Lightning Experience and all versions of the mobile app. These resources aren’t supported in other containers, such as Lightning Components for Visualforce, Lightning Out, or Communities. This is true even if you access these containers inside Lightning Experience or the Salesforce mobile app.

Why: In standard navigation Lightning apps, you can use the lightning:navigation component to navigate to a custom component that implements lightning:isUrlAddressable. Using lightning:navigation with pageReference provides the following benefits over the now deprecated force:navigateToComponent for standard navigation Lightning apps.

  • Gives you control over whether a component can be opened programmatically, and which attributes can be dynamically set when the component is opened.
  • Control and manage which URL parameters are used in your component.
  • Future-proofs your apps from changes in URL format.
  • Generates a user-friendly URL for these components.

A page reference is associated with a particular type, which provides a set of attributes that are applicable for all pages of that type. The following types are supported.

  • Knowledge Article Page
  • Lightning Component (must implement lightning:isUrlAddressable)
  • Named Page
  • Navigation Item Page
  • Object Page
  • Record Page
  • Record Relationship Page
Note

Note

The lightning:isUrlAddressable interface enables you to generate a user-friendly URL for a Lightning component with the pattern /cmp/componentName instead of the base-64 encoded route you get with force:navigateToComponent. We recommend that you use lightning:isUrlAddressable instead of force:navigateToComponent, which is now deprecated.

In Lightning console apps, you can open custom components that implement lightning:isUrlAddressable via openSubtab(), even from utilities.

See Open Custom Lightning Components in Workspace Tabs and Subtabs.