How can I add some parameters in the new component in NavigationMixin?

702    Asked by darsh_6738 in Salesforce , Asked on Mar 7, 2023

I am using NavigationMixin to navigate from one lwc to another lwc (app page in a custom tab) like this:

navigateToTabPage() { // Navigate to a specific CustomTab. this[NavigationMixin.Navigate]({ type: 'standard__navItemPage', attributes: { apiName: 'TABNAME' } }); }

How can I add some parameters (for example an Id) and how can I handle this parameters in the new component ?

Answered by Darsh K

To add some parameters in the new component in NavigationMixin -

standard__navItemPage PageReference Type does not have any property other than apiName which is the unique name of the CustomTab. It means you can not pass anything other than that.
You should use standard__component PageReference Type. To make an addressable Lightning web component, embed it in an Aura component that implements the lightning:isUrlAddressable interface.
{ type: 'standard__component', attributes: { componentName: 'c__MyLightningComponent' }, state: { c__counter: '5' } }

You can pass any key and value in the state object. The key must include a namespace, and the value must be a string.



Your Answer

Interviews

Parent Categories