You can navigate to a component that defines the lightning__UrlAddressable target in the component’s .js-meta.xml configuration file. lightning__UrlAddressable is supported only in Lightning Experience and the Salesforce mobile app. It’s also supported in custom apps, such as in a Lightning console app. This target isn’t supported in Experience Builder sites, since it interferes with custom domain and CDN support.
To make the component available for navigation, set the <isExposed> tag to true. The <apiVersion> tag has no impact on the lightning__UrlAddressable target and can be set to an earlier version.
The standard__component page reference type has the componentName attribute that takes in a component name in the format namespace__componentName.
You can pass any key and value in the state object. The key must include a namespace, and the value must be a string. If you don’t have a registered namespace, add the default namespace of c__, like with c__MyComponent.
Pass State Information to a Component
A component with the lightning__UrlAddressable target has a URL with the format /lightning/cmp/c__MyComponent?c__mystate=value. You can pass a property value to your URL-addressable component when navigating like this.
In your URL-addressable component, myComponent, use a getter to return the property value from the state object.
1// myComponent.js2import{LightningElement, wire, api}from "lwc";3import{CurrentPageReference}from "lightning/navigation";45export default class MyComponent extends LightningElement{6 @wire(CurrentPageReference)7 currentPageRef;89 @api propertyValue;1011 get propertyValue(){12 return this.currentPageRef.state.c__propertyValue;13}14}
Example: Navigate to a Component From an App Page
This example shows a component navToComponent with a button that opens a URL-addressable component. Its .js-meta.xml configuration file includes the lightning__AppPage target only. It assumes that you’ve added the navToComponent component to an app page using Lightning App Builder.
1<!-- navToComponent.html -->2<template>3 <lightning-button4 label="Go to Component"5 class="slds-var-m-around_medium"6 onclick={navigateToComponent}7 ></lightning-button>8</template>
1// navToComponent.js2import{LightningElement}from "lwc";3import{NavigationMixin}from "lightning/navigation";45export default class NavToComponent extends NavigationMixin(LightningElement){6 navigateToComponent(){7 this[NavigationMixin.Navigate]({8 // Pass in pageReference9 type: "standard__component",10 attributes:{11 componentName: "c__myComponent",12},13});14}15}
Example: Navigate to a Component in a Lightning Console App
This example shows a component workspaceOpenTab with a button that opens a URL-addressable component in a new workspace tab. Its .js-meta.xml configuration file includes the lightning__AppPage target only. It assumes that you’ve added the workspaceOpenTab component to a Lightning console app.
myComponent displays the URL and page reference information that’s defined by the workspaceOpenTab component. The myComponent.js-meta.xml configuration file includes the lightning__UrlAddressable target.
The component’s JavaScript uses the CurrentPageReference wire adapter to return page reference information. In this example, the URL returns https://MyDomainName.my.salesforce.com/lightning/cmp/c__myComponent?c__mystate=value&uid=_uniqueId_.
In a Lightning console app, navigating to a component displays the component in a new tab. To prevent the app from opening a new tab if the tab with the component is already opened, pass in a uid value to the state object.
This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.