2

I'm opening a tab using workspace API openTab() with pageReference passing some values within state.

Then I want to open the same tab by clicking a different link and passing different parameters. So by using the pageReference how can I open the same tab with these different parameters? I know I can open the tab using URL argument. But it doesnt work in my case!

Any suggestions?

2

The reason it does not change is because you will be getting the parameters from state only on init and initialised only once and whenever you want to load the same component again with different parameters, init will not be invoked again.

You should be using change handler on pageReference so that you can get the parameters from state whenever its changed. You can check this documentation

Sample:

<aura:component implements="lightning:isUrlAddressable" description="c:helloTarget component">
    <aura:attribute name="firstname" type="String" />
    <!-- Add an "init" handler to handle the first "v.pageReference" value -->
    <aura:handler name="init" value="{!this}" action="{!c.onPageReferenceChange}"/>
    <!-- Add a "change" handler to handle all changes to the "v.pageReference" value -->
    <aura:handler name="change" value="{!v.pageReference}" action="{!c.onPageReferenceChange}"/>
    Hello {!v.firstname}.
</aura:component>

CONTROLLER:

({
    onPageReferenceChange: function(cmp, evt, helper) {
        var myPageRef = cmp.get("v.pageReference");
        var firstname = myPageRef.state.c__firstname;
        cmp.set("v.firstname", firstname);
    }
})

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.