Skip to main content
Navigate to standard record pages using the lightning/navigation service. This component demonstrates navigating to both view and edit modes.

Source

force-app/main/default/lwc/navToRecord/navToRecord.js

Usage

import { LightningElement, wire } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import getSingleContact from '@salesforce/apex/ContactController.getSingleContact';

export default class NavToRecord extends NavigationMixin(LightningElement) {
    @wire(getSingleContact) contact;

    navigateToContact() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.contact.data.Id,
                objectApiName: 'Contact',
                actionName: 'view'
            }
        });
    }

    navigateToEdit() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.contact.data.Id,
                objectApiName: 'Contact',
                actionName: 'edit'
            }
        });
    }
}
Extend your component with NavigationMixin to access navigation capabilities:
export default class NavToRecord extends NavigationMixin(LightningElement) {
    // component code
}

PageReference

View Record

type
string
required
Set to standard__recordPage for record pages
attributes.recordId
string
required
The ID of the record to display
attributes.objectApiName
string
required
The API name of the object (e.g., ‘Contact’, ‘Account’)
attributes.actionName
string
required
Set to view to display the record in view mode

Edit Record

type
string
required
Set to standard__recordPage for record pages
attributes.recordId
string
required
The ID of the record to edit
attributes.objectApiName
string
required
The API name of the object (e.g., ‘Contact’, ‘Account’)
attributes.actionName
string
required
Set to edit to display the record in edit mode

Key Features

  • Navigate to record view pages
  • Navigate to record edit pages
  • Type-safe navigation with PageReference
  • Supports all standard and custom objects

Build docs developers (and LLMs) love