- Create a cacheable, Aura Enabled Apex method that returns an object holding the Page.pagename.getUrl()** value and an indication whether the page is in a community (using Site.getSiteId() != null)
- Have the LWC invoke this method using a wire
- Have the LWC use the returned URL value:
- When in a community: just use window.open with the URL with added query parameters (since communities don't support navigation to a page reference as a standard web page)
- When not in a community: with NavigationMixin but treating it as a "standard_webPage". The URL itself has the required query parameters added before being used as the "url" attribute for the NavigationMixin.generateUrl call. The mixin promise uses window.open.
** Update:
We actually found that when using with communities that include a URL suffix that the Page.pagename.getUrl() did not add the community URL suffix and therefore didn't work. This was remedied by having a known static resource and using the following:
String theURL = PageReference.forResource('theknownresource').
substringBefore('/resource/') +
Page.pagename.getUrl();
This then works outside communities, in a community with no URL suffix, in a community with a URL suffix and in a community with multiple URLs.