Gets the current page reference from the router container. This wire is also available in Lightning Experience.
Properties
None
Syntax
import { LightningElement, wire } from "lwc";
import { CurrentPageReference } from "lightning/navigation";
export default class Example extends LightningElement {
@wire(CurrentPageReference)
propertyOrFunction;
}
Returns
- A
PageReferenceobject containing a reference to the current page.
Example
import { LightningElement, wire } from "lwc";
import { CurrentPageReference } from "lightning/navigation";
export default class Example extends LightningElement {
// Subscribe to page reference updates
@wire(CurrentPageReference)
printPageName(pageRef) {
console.log(`Page name: ${pageRef ? pageRef.attributes.name : ""}`);
}
}