Sub topic 7
Named, web, app, and nav item pages
The previous chapters covered record and object pages. This chapter covers four more page reference types: standard__namedPage, standard__webPage, standard__app, and standard__navItemPage. They all work through the same call, this[NavigationMixin.Navigate](pageReference). Only the type and attributes change.
This chapter assumes you know how to apply NavigationMixin to a component class and what a PageReference object looks like (a type, an attributes object, and an optional state object). It also assumes you are comfortable with @api properties and event handlers.
Choosing the right page type
Each type targets a different kind of destination.
| Page reference type | Destination | Required attribute |
|---|---|---|
| `standard__namedPage` | A standard Lightning Experience page such as Home or Chatter | `pageName` |
| `standard__webPage` | An external URL | `url` |
| `standard__app` | A Lightning app, optionally at a specific page inside it | `appTarget` |
| `standard__navItemPage` | A custom tab (nav item) | `apiName` |
Named pages
A named page is a standard page that Salesforce identifies by a fixed name. Set the pageName attribute to one of these values:
homeopens the Home page.chatteropens the Chatter page.todayopens the Today page.dataAssessmentopens the Data Assessment page.filePreviewopens the file preview. It also needs a file ID instate.
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
attributes: {
pageName: 'home'
}
});Experience Cloud sites use a different type, comm__namedPage, whose attribute is name. That name is the API name of a site page, for example Home. Do not use standard__namedPage for pages that belong to a site.
Web pages
Use standard__webPage to send the user to an address outside Salesforce. The url attribute is the only one you need. Use a full URL that starts with https://.
this[NavigationMixin.Navigate]({
type: 'standard__webPage',
attributes: {
url: 'https://developer.salesforce.com/docs'
}
});Treat the URL as data you control. If any part of it comes from user input or a record field, validate it before navigating. Otherwise a stored value could send users to an unexpected site.
App pages
standard__app opens a Lightning app. The appTarget attribute has the form namespace__DeveloperName. For an app with no namespace, use c__ followed by the app's developer name. Standard apps use the standard__ prefix.
You can also pass a nested pageRef. Salesforce opens the app first and then shows that page inside it.
this[NavigationMixin.Navigate]({
type: 'standard__app',
attributes: {
appTarget: 'c__FieldService',
pageRef: {
type: 'standard__objectPage',
attributes: {
objectApiName: 'Account',
actionName: 'list'
},
state: {
filterName: 'Recent'
}
}
}
});The nested pageRef is a complete PageReference with its own type, attributes, and state. If you leave it out, the user lands on the app's default page.
Nav item pages
A nav item page is a custom tab. It can wrap a Lightning page, a Visualforce page, or a Lightning component. Set apiName to the API name of the tab. If the tab comes from a namespaced package, include the namespace prefix.
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: {
apiName: 'Reports_Dashboard'
}
});Reports_Dashboard is an example name. It must match a custom tab that exists in the org. The user must also have permission to see that tab.
A complete example
This component has one button for each page type. The template calls four handlers, and the class applies NavigationMixin to LightningElement.
<template>
<lightning-card title="Go somewhere">
<div class="slds-var-p-around_medium">
<lightning-button label="Home" onclick={goHome}></lightning-button>
<lightning-button label="Docs" onclick={goDocs}></lightning-button>
<lightning-button label="Open app" onclick={goApp}></lightning-button>
<lightning-button label="Open tab" onclick={goTab}></lightning-button>
</div>
</lightning-card>
</template>import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class GoSomewhere extends NavigationMixin(LightningElement) {
goHome() {
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
attributes: { pageName: 'home' }
});
}
goDocs() {
this[NavigationMixin.Navigate]({
type: 'standard__webPage',
attributes: { url: 'https://developer.salesforce.com/docs' }
});
}
goApp() {
this[NavigationMixin.Navigate]({
type: 'standard__app',
attributes: { appTarget: 'c__FieldService' }
});
}
goTab() {
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: { apiName: 'Reports_Dashboard' }
});
}
}For this to run in your org, the goApp and goTab handlers need a real app named FieldService and a real tab named Reports_Dashboard. Replace those names with ones that exist.
Common errors
Most failures with these page types come from a small set of causes.
- Wrong attribute name.
standard__namedPageusespageName,comm__namedPageusesname, andstandard__navItemPageusesapiName. A misspelled attribute usually fails silently or shows an error page, and your code throws nothing. - Missing namespace prefix. An app target like
FieldServicedoes not resolve. It must bec__FieldServicefor an unnamespaced custom app. - Relative or incomplete URLs. A
standard__webPageURL such aswww.example.comis treated as a relative path and does not leave Salesforce. Always include the scheme. - Missing access. If the user cannot see the app or tab, navigation fails even though the page reference is correct. Test with a non-admin profile.
- Wrong context. Page references such as
standard__appandstandard__navItemPagetarget Lightning Experience. In an Experience Cloud site, use thecomm__types instead.
Exercise
Exercise
A button handler runs this[NavigationMixin.Navigate]({ type: 'standard__app', attributes: { appTarget: 'SalesOps' } });. The org has a custom app whose developer name is SalesOps and that has no namespace. The user lands on an error page. What is wrong, and what is the corrected call? What would you add to open the Accounts list inside that app?
Show answer
The appTarget is missing the namespace prefix. For an app with no namespace it must be c__SalesOps. The corrected call uses attributes: { appTarget: 'c__SalesOps' }. To open the Accounts list inside the app, add pageRef: { type: 'standard__objectPage', attributes: { objectApiName: 'Account', actionName: 'list' } } to attributes, next to appTarget.