1

I have a lwc inside an aura component urlAddressable. The idea is to navigate to that lwc from a record page, and passing the record id and maybe other data via query paramaters in the url, for example:

https://virtualseller-dev-ed.lightning.force.com/lightning/cmp/c__visualizarCuotas?id=aE00009978ffttMOA&price=25600

And then, retrieve the id and other params and do several things depending on what is arriving. Is this possible? I read that using currentPageReference I can get the parameters but I don't know if it works for urlAddressable aura components, with a nested LWC.

1 Answer 1

0

Here's a sample LWC JS to get values from URL Parameters.

import { LightningElement, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
export default class testLWCComponent extends LightningElement {
    currentPageReference = null;
    urlParameters = null;
    /* Params from Url */
    recordId= null;
    price = null;
    //Add More Parameters as per your need
    
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
       if (currentPageReference) {
          this.urlParameters = currentPageReference.state;
          this.setParametersFromUrl();
       }
    }
    setParametersFromUrl() {
       this.recordId = this.urlParameters.id || null;
       this.price = this.urlParameters.price || null;
    }
}

There are multiple ways to achieve passing values as a URL parameter from a Record Detail page. The easiest would be a formula field. Create a hyperlink in the formula field as add the required URL parameters. Let me know if this helps.

1
  • thanks! I had read about currentPageReference, but it does work for nested lwc in aura components? So if it is the urlAddressable aura component that receives the parameters, the LWC has access to them to? Jun 7, 2021 at 15:02

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.