Navigation

lightning:navigation

Generates URL for a given pageReference. This component requires API version 43.0 and later.

For Aura components only. For LWC development, use lightning/navigation.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Mobile Offline

Use lightning:navigation component to navigate to a given pageReference or to generate a URL from a pageReference.

The following example generates a URL to an Account Object home based on its pageReference and sets the URL on an <a> element. The example assumes that you're creating the component for a custom Lightning Component tab or a Lightning page by implementing force:appHostable and flexipage:availableForAllPageTypes.

In your client-side controller, set the pageReference attribute for the Account home page. Set the URL on your link using the generateUrl() method, which is useful for opening links in a new tab. Depending on whether you’re using the new URL format available as part of the Summer ’18 critical update, you might see a URL that begins with the new format /lightning/cmp/ or the old format one/one.app#/cmp/.

You can also navigate directly to a page using a onclick handler.

In your client-side controller, use the navigate() method to navigate to the page.

PageReference is a reference to a page, providing a well-defined structure that describes the page type and its corresponding values. You should use the PageReference definitions instead of attempting to parse the URL directly. The following PageReference properties are supported.

PropertyTypeDescription
typestringRequired. The API name of the PageDefinition.
attributesobjectRequired. Values for each attribute specified by the PageDefinition.
stateobjectAdditional parameters, such as filterName, which is tied to the query string of the URL in Lightning Experience. The routing framework doesn't depend on state to render a page.

For example, to set the route to /lightning/o/Account/list?filterName=MyAccounts:

For more information on the PageReference object, see the Lightning Aura Components Developer Guide.