1

When component is loaded in lightning experience, we can get the state of page ref using below:

doInit : function(component, event, helper) {
    let pr = component.get("v.pageReference");
    if(pr)
        component.set("v.attr",pr.state.c__myAttr);
}

We are able to navigate to a custom page in community using below page reference.

{
        type: "comm__namedPage",
        attributes: {
            pageName: "custom-page"
        },
        state: {
            c__myAttr: "some value"
        }
    }

Also we are getting the parameters in URL like /s/custom-page?c__myAttr=some+value

However, we have the component inside the custom page which is not able to get the page ref state parameters.

I know that we can get url through window.location.href and get parameter out of it. But is there a standard way of lightning component in custom page to get page ref and its state?

1 Answer 1

1

state property gets ignored with out any error in communities for navigationservice, so we came up with session store below snippet works for our communities.

function(component, event, helper) {
    event.preventDefault();
    var navService = component.find("navService");
    var pageReference = {
        type: "comm__namedPage",
        attributes: {
            pageName: "some-page-name"
        },
        state: {
            c__myAttr: 'some value'
        }
    };
    sessionStorage.setItem('pageTransfer', JSON.stringify(pageReference.state));
    navService.navigate(pageReference);
}

loading cmp

var localStuff = sessionStorage.getItem('pageTransfer');
if (localStuff) {
    var state = JSON.parse(localStuff);
    // Do the needed stuff here
}

You must log in to answer this question.

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