I have a request to populate some field on component which resides on almost every page in Lightning community. The field needs to be populated with page name it resides on dynamically. Currently only solution i can think off is to get window location URL and split the string to get page name. Is there better approach for this?

1 Answer 1


You can make use of the Renderer element in the aura component bundle that outputs the page name when the Web Page is ready as follow -

 afterRender  : function(cmp, helper){


This would give you the page name when the document is ready

Now, you would want the page name to change dynamically as you navigate in your community. For that you can do the following,

Create an aura handler that looks for url change as follows -

<aura:handler event="forceCommunity:routeChange" action="{!c.handleRouteChange}"/>

And next for the action use the js code as below -


This would reload the page name in the pageName attribute when there is a change in URL, thereby making it dynamic.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .