function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kelvin Tam 11Kelvin Tam 11 

lightning web component get url parameter

Hi All,

Would the lightning web component available to get the url parameter?

The url rediret everytime when enter salesforce ligthning.

Thank you
YOGESH BISHT2YOGESH BISHT2
Hi kelvin,
If you are looking passing parameter with on URL you can use this :

import { NavigationMixin } from 'lightning/navigation';

connectedCallback() { 
this[NavigationMixin.GenerateUrl]({ "type": "standard__webPage", "attributes": { "url": "http://salesforce.com" } }, { replace: true })
}

Please let me know if it helps.

Thanks
 
Ravi Dutt SharmaRavi Dutt Sharma
You can use below function to get url parametes as key value pairs:
 
getQueryParameters() {

        var params = {};
        var search = location.search.substring(1);

        if (search) {
            params = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', (key, value) => {
                return key === "" ? value : decodeURIComponent(value)
            });
        }

        return params;
    }

 
Kelvin Tam 11Kelvin Tam 11
Hi YOGESH BISHT2 & Ravi Dutt Sharma

Thank you for your answer.

My current condition is below 

once I press enter for below url
https://salesforce.com/lightning/page/home?test=test

the browser then redirect to 
https://salesforce.com/lightning/page/home

therefore I cannot catch the "test=test" information.

Thank you