Has anyone successfully used the pubsub module from lwc-recipes to enable inter-component communication in a Lightning Community? The registerListener function in the pubsub module throws an error because the pageRef property is undefined. Or is pubsub designed for Lightning Experience only?


The pub-sub module checks for page references when firing events, so that the event is scoped and only in the current page.

In Communities, we actually now support lightning-navigation as of Spring '19: http://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_networks_navigationchanges.htm

However, there are some limitations, currently CurrentPageReference in LWC is not supported like: @wire(CurrentPageReference)currentPageReference;, which is why you are getting undefined page references. We are currently working on supporting it, so it should be out soon!

For a temporary solution, you can just remove all the pageRef checking in pubsub :). Here's a quick example: https://gist.github.com/kmesic/262887799fb70be94707cb0b87936e7b

Also, we are soon going to be releasing a LWC sample that will work in Communities by default! This should help clear up any confusion when using LWC in Communities.

  • 1
    Thank you so much, Kenan! That's great news.
    – Arlene
    Mar 19 '19 at 20:56
  • @kenan, is this being supported natively now. May 31 '20 at 10:47

Pub - Sub model uses Page reference and lightning-navigation and as lightning - navigation is supported only in Lightning Experience and Mobile App, the pub - sub module currently won't work in communities.

Src : https://github.com/trailheadapps/lwc-recipes/issues/86

  • 1
    Adding to this, even the aura version doesn't support community context so it's unlikely the LWC would too.
    – tsalb
    Mar 17 '19 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.