CurrentPageReference

Gets the current page reference from the router container. This wire is also available in Lightning Experience.

Properties 

None

Syntax 

1import { LightningElement, wire } from "lwc";
2import { CurrentPageReference } from "lightning/navigation";
3
4export default class Example extends LightningElement {
5  @wire(CurrentPageReference)
6  propertyOrFunction;
7}

Returns 

  • A PageReference object containing a reference to the current page.

Example 

1import { LightningElement, wire } from "lwc";
2import { CurrentPageReference } from "lightning/navigation";
3
4export default class Example extends LightningElement {
5  // Subscribe to page reference updates
6  @wire(CurrentPageReference)
7  printPageName(pageRef) {
8    console.log(`Page name: ${pageRef ? pageRef.attributes.name : ""}`);
9  }
10}

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!