NavigationMixin

You can use NavigationMixin instead of the navigate() and generateUrl() APIs. Both options offer the same functionality, but only NavigationMixin is compatible with Lightning Experience. If you’re writing a component for use in both LWR and Lightning Experience, choose NavigationMixin.

Syntax 

1import { LightningElement } from "lwc";
2import { NavigationMixin } from "lightning/navigation";
3
4const pageRef = {
5  type: "standard__recordPage",
6  attributes: {
7    recordId: "001xx000003DGg0AAG",
8    objectApiName: "Account",
9    actionName: "view",
10  },
11};
12
13export default class Example extends NavigationMixin(LightningElement) {
14  // Navigate to a page reference
15  navPageRef() {
16    this[NavigationMixin.Navigate](pageRef);
17  }
18  // Generate a URL for a page reference
19  getUrl() {
20    this[NavigationMixin.GenerateUrl](pageRef).then((url) => console.log(url));
21  }
22}

See Also

Developer Preview Feature

Feature is available as a developer preview. Feature is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Do not implement functionality developed with these commands or tools.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!