0

Hi I need some assistance for one of the scenario, i am trying to open a ABC LWC(Target) Component from another XYZ(Source) Lightning Web Component in which target ABC LWC is Wrapped inside the aura Named as (qwert) component. the problem is that whenever user clicks new sub tab gets opened, is there any way if the tab is already open then close the existing tab and open a new tab every time.

Below is my code :

/

/Code in the XYZ invoking AURA Component:
clickOnNext(evt) {
        this[NavigationMixin.Navigate]({
            type: 'standard__component',
            attributes: {
                componentName: 'c_qwert'
            },
            state: {
                c__ITC: this.ITCRe,
            }
        });
    }

//AURA Component opening up he target lwc ABC

<aura:component implements='flexipage:availableForAllPageTypes,lightning:isUrlAddressable access:global'>
    <lightning:workspaceAPI aura:id='WAPI'/>
    <aura:handler name='init' value='{!this}' action='{!c.init}'/>
      <c:ABC/>
</aura:component>

({
    init: function (component, event, helper) {
        let workspaceAPI = component.find('WAPI');
        workspaceAPI.getEnclosingTabId().then((response) => {
            let idOfOpne= response.tabId;
            workspaceAPI.setTabLabel({
                tabId: idOfOpne,
                label: 'Loading This Tab'
            });
            
        })
        
)} 

I am doing something like below link wrapped inside Aura: https://salesforcediaries.com/2020/06/07/navigate-to-lightning-web-component-from-another-lightning-web-component/

Kindly help me out to restrict the user on the tab if it is already open. i am trying to achieve something like this : https://help.salesforce.com/articleView?id=000338343&type=1&mode=1

2
  • is there any solution available for this – dunkrit Nov 23 '20 at 16:11
  • can someone please help me out...??? – dunkrit Nov 24 '20 at 8:28
0

You should be able to do something like this:

workspaceAPI.getFocusedTabInfo().then(function(response) {
    var focusedTabId = response.tabId;
    workspaceAPI.closeTab({tabId: focusedTabId});
})
.catch(function(error) {
    console.log(error);
});
1
  • hi @willards i tried that but the issue with this is that it will close all the sub tabs..i jst need if it is open then it should re-open the same subtab – dunkrit Nov 23 '20 at 16:32

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.