I have created a aura component which uses the @api recordId in order to query some data from the apex controller. It all works properly when using the aura component on the record detail page.
The problem is that I need to open the LWC in a new browser tab. I'm not sure what the right approach is in this case. So far I have created two Lightning components in order to achieve this:
The first one(testContainer) includes the LWC:
<aura:component implements="force:lightningQuickActionWithoutHeader,force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId">
<c:testaura component name="Test" />
</aura:component>
The second one just opens the first one in a new tab and passes over the record id:
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" >
<div class="slds-text-align_center">Loading...</div>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
and the controller:
({
doInit : function(component, event, helper) {
var evt = $A.get("e.force:navigateToComponent");
evt.setParams({
componentDef : "c:testContainer",
componentAttributes: {
recordId : component.get("v.recordId")
}
});
evt.fire();
}
})
Is there a simpler approach to open a LWC in a new tab from a record detail page? If not, then how can I get the record id from the aura component? Using this approach is seems like I cannot retrieve it.
Best Answer
e.force:navigateToComponent
is deprecated. I wont recommend using it.Instead use lightning:navigation , you generate state(aka URL params) by setting page references.
JS:
Now you have to make your LWC component listen to pageReference and get state(the recordId that we sent)
you can do that in your lwc by declaing @wire(CurrentPageReference)