Lightning Navigation
Use the lightning/navigation API to navigate to different pages within your site, generate URLs to different routes, and get the current pageReference object.
See PageReference Types in the Lightning Web Components Developer Guide.
Aura templates support comm__namedPage schemas that use the name attribute (added in Spring ’20) and the pageName attribute (deprecated in Spring ’20). In LWR templates, only the name attribute is supported. The name of a page is its API name, which is configurable during page creation and visible on the page properties.
URLs for record detail pages behave a little differently in LWR sites than in Aura sites.
- For pages of type
standard__recordPage, the URLs that are generated using thelightning/navigationAPI includedetailas the recordName in the URL path. The proper record name is used when the user actually visits the page through a canonical URL redirect. - If the current user visits a record detail page but doesn’t have access to the current record, there’s no canonical URL redirect and the record name can’t be resolved.
- There’s no support for
pageReferencetypestandard__namedPage. Usecomm__namedPageinstead. - When URL slugs are enabled for LWR Commerce stores, in pages of type
standard__recordPage,urlPathis supported for Category object pages, andurlNameis supported for Product object pages. Include theurlNameattribute for Product andurlPathattribute for Category in thestandard__recordPagepageReference attributes along with therecordId.
When you develop custom Lightning web components that contain links, use the lightning/navigation API to generate URLs for the href values as an SEO best practice. See Basic Navigation in the Lightning Web Components Developer Guide.
- The
comm__loginPagepageReferencetype isn’t supported. Instead, navigate to the login page as a regularcomm__namedPage. - The
objectApiNameattribute is required when navigating to pages of typestandard__recordPageorstandard__recordRelationshipPage. - The
actionNameattribute isn’t enforced as required when navigating to pages of typestandard__recordPageorstandard__recordRelationshipPage. However, includingactionNameremains a recommended best practice.