Sub topic 7
Named, web, app, and nav item pages
This chapter assumes you can already call this[NavigationMixin.Navigate] and know that a PageReference is an object with a type, attributes, and optional state. It covers four page types that don't point at a record or an object.
Choosing a page type
Each type has its own required attributes.
| Type | Goes to | Key attribute |
|---|---|---|
| `standard__namedPage` | A well-known page such as Home or Chatter | `pageName` |
| `standard__webPage` | An external URL | `url` |
| `standard__app` | A Lightning app | `appTarget` |
| `standard__navItemPage` | A custom tab (nav item) | `apiName` |
One component, four destinations
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class OtherPages extends NavigationMixin(LightningElement) {
goHome() {
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
attributes: { pageName: 'home' }
});
}
goExternal() {
this[NavigationMixin.Navigate]({
type: 'standard__webPage',
attributes: { url: 'https://developer.salesforce.com' }
});
}
goToSalesApp() {
this[NavigationMixin.Navigate]({
type: 'standard__app',
attributes: { appTarget: 'standard__LightningSales' }
});
}
goToTab() {
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: { apiName: 'Inventory_Dashboard' }
});
}
}Inventory_Dashboard is a placeholder. Replace it with the API name of a custom tab in your org.
Details for each type
- Named pages.
pageNametakes a fixed set of values. In Lightning Experience, common ones arehome,chatter, andtoday. In Experience Cloud sites, the available names depend on the site. An unsupported name leads to an error page, not an exception in your code. - Web pages.
urlmust be a full address, includinghttps://. Use this type for links that leave Salesforce. Don't use it for internal pages, because PageReferences for those keep the user inside the app. - Apps.
appTargetis the app's developer name, written asnamespace__DeveloperName. Custom apps in the default namespace look likec__MyApp. Standard apps use thestandard__prefix, as in the example above. You can also pass the app ID. - Nav item pages.
apiNameis the API name of a custom tab. It is the tab's name, not the name of the component inside it. The tab must exist and the user must have access to it.
Common mistakes
- Leaving out
https://in a web page URL. - Using a component name where
apiNameexpects a custom tab name. - Forgetting the
c__prefix on a custom app inappTarget. - Calling
this[NavigationMixin.Navigate]from a class that does not extendNavigationMixin(LightningElement).
Exercise
A button handler must open the custom tab whose API name is Order_Tracker. Which type and attribute do you use, and what is the wrong choice a beginner often makes?
Show answer
Use type standard__navItemPage with attributes: { apiName: 'Order_Tracker' }. A common mistake is passing the name of the LWC that the tab displays instead of the tab's own API name.