Route Change

forceCommunity:routeChange

Indicates that a page's url is changed.

For Use In

Experience Builder Sites

::::::tabset{tabs='["Develop", "Specifications"]'}

:::::tab

forceCommunity:routeChange is fired when a page’s URL changes. Custom Lightning components can listen to this system event and handle it as required—for example, for analytics or SEO purposes.

This example listens to the event and updates a counter that denotes the number of times the route has changed.

<aura:component implements="forceCommunity:availableForAllPageTypes">
    <aura:attribute name="routeChangeCounter" default="0" type="Integer" required="false"/>
    <aura:handler event="forceCommunity:routeChange" action="{!c.handleRouteChange}"/>
    <h1>Route was changed: {!v.routeChangeCounter} times</h1>
</aura:component>

This client-side controller updates the counter.

handleRouteChange : function(component, event, helper) {
    component.set('v.routeChangeCounter', component.get('v.routeChangeCounter') + 1);
}

This event is supported in Aura-based Experience Builder sites only.

:::::

:::::tab

No specifications to show

::::: ::::::