I'm trying to retrieve url parameters through a lightning web component in my Community.

For exemple : wwww.my-community.com/my-page?test=true

How can I, in the new LWC framework, get the parameter "test" and it's value ?

Thanks for your answers ;)


If the question was if the LWC Framework provide an utility - then no not that i am aware of.

Which means you can use every js snippet you will find somewhere in the web like

    parameters = {};

    connectedCallback() {

        this.parameters = this.getQueryParameters();

    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;

That will return you an key/value pair of your parameters for further usage in your component

  • Thank you ! :) It works :) I used another script in js because LWC do not have a native function – FabienHuot Jun 21 '19 at 9:52
  • Don't forget that only paramters with names starting with "c__" will be kept in the location.href – Ombrelin Jan 10 at 11:08

Another approach with using URL.searchParams:

The searchParams readonly property of the URL interface returns a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.

connectedCallback() {
    const param = 'test';
    const paramValue = this.getUrlParamValue(window.location.href, param);

getUrlParamValue(url, key) {
    return new URL(url).searchParams.get(key);

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.