How can developers navigate to object home views and record creation pages using NavigationMixin?
Answer
Basics: Hard-coded URLs break across Lightning Experience, Experience Cloud and mobile. A PageReference is a declarative JSON description of a destination; the framework turns it into the right URL for the current container. Import NavigationMixin from lightning/navigation and wrap the base class: class X extends NavigationMixin(LightningElement).
How it works: this[NavigationMixin.Navigate](ref) navigates; this[NavigationMixin.GenerateUrl](ref) returns a Promise of a URL (for use in href). Common references: object home or list { type: 'standard__objectPage', attributes: { objectApiName: 'Account', actionName: 'home' | 'list' }, state: { filterName: 'Recent' } }; new record actionName: 'new'; record { type: 'standard__recordPage', attributes: { recordId, objectApiName, actionName: 'view' | 'edit' | 'clone' } }; related list standard__recordRelationshipPage with relationshipApiName; plus standard__navItemPage (custom tab), standard__namedPage, standard__webPage and comm__namedPage for sites.
Advanced / deep dive: Pre-populate a new record using encodeDefaultFieldValues from lightning/pageReferenceUtils and passing state: { defaultFieldValues: ... }. The optional second argument true replaces the current history entry instead of pushing a new one. CurrentPageReference wire (also in lightning/navigation) reads state and parameters of the current page. Navigation inside Flow screens must use the flow navigation events rather than NavigationMixin. In Jest, the mixin is stubbed; verify behavior by mocking . Page reference types and properties differ between Lightning Experience, mobile and Experience Cloud (LWR vs Aura sites), so test in each. Keep keys prefixed with a namespace (e.g., ) for custom parameters, since non-prefixed keys may be ignored or reserved.