---
title: "GET URL Params"
url: "https://blog.beyondthecloud.dev/tips/get-url-params"
category: "LWC"
published: "2024-01-02"
---

# GET URL Params

The easiest way to obtain URL parameters is by using CurrentPageReference. Below, you can find an example of currentPageReference. As you can see, all parameters are stored in the state…

### URL Params in LWC

How to get URL Params in LWC?

The easiest way to obtain URL parameters is by using CurrentPageReference. Below, you can find an example of currentPageReference. As you can see, all parameters are stored in the state property.

![GET URL Params — screenshot 1](https://blog.beyondthecloud.dev/tips/get-url-params/fig-1.webp)

```javascript
// currentPageReference
{
    attributes: {
        name: URL_Test_Page__c
    },
    state: {
        lang: en_US,
        type: test-type,
        id: 000000000001
    },
    type: comm__namedPage
}
```

Add the @wire(CurrentPageReference) method to your LWC component. The method will automatically fire every time URL parameters change.

```javascript
import { LightningElement, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';

export default class MyComponentName extends LightningElement {

    urlId = null;
    urlLanguage = null;
    urlType = null;

    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            this.urlId = currentPageReference.state?.id;
            this.urlLanguage = currentPageReference.state?.lang;
            this.urlType = currentPageReference.state?.type;
        }
    }
}
```
