User changes current page

webflow.subscribe("currentpage", callback)

Use this method to start listening for specific events in your App. In this case, we’re listening for when a user selects a new page in the Designer.

Syntax

1 webflow.subscribe( event: 'currentpage',callback: (element: null | AnyElement) => void): Unsubscribe;

Parameters

event : "currentpage"

The name of the event to subscribe to.


callback: (page: Page => void)

The callback function to execute when the event occurs. The page parameter should be the page you’re watching.


Returns

Unsubscribe

This is a special function you receive after subscribing. When you no longer want to listen to the event, call this function to stop receiving notifications.

Example

1// Subscribe to changes in the selected page
2const selectedPageCallback = (page: Page | null) => {
3 if (page) {
4 console.log('Selected Page:', page);
5 } else {
6 console.log('No element is currently selected.');
7 }
8}
9
10const unsubscribeSelectedElement = webflow.subscribe('currentpage', selectedPageCallback);