DEV Community

bhanukarkra
bhanukarkra

Posted on

Check you are on which page from LWC

To check if the Lightning component is in Lightning Community Page or in Salesforce Lightning CRM page, we can make use of Site Class‘s method – getSiteType().

this return these values

Image description

Create an @AuraEnabled method in Apex Controller:

@AuraEnabled
public static String getSiteType() {
    return Site.getSiteType();
Enter fullscreen mode Exit fullscreen mode

controller to fetch

var communityPageKeys = ['ChatterNetwork', 'ChatterNetworkPicasso'];
var action = component.get("c.getSiteType");

action.setCallback(this, function (response) {
    if (response.getState() === "SUCCESS") {
        if (communityPageKeys.indexOf(response.getReturnValue()) < 0) {
            // This is not a community page
        } else {
            // This is a community page
        }
    }
});

$A.enqueueAction(action);

Enter fullscreen mode Exit fullscreen mode

Reference [https://vijayasankarn.wordpress.com/2018/02/12/lightning-component-is-it-in-community-or-in-lightning-page/]

Top comments (0)