1

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 ;)

4

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();
        console.log(this.parameters);
    }

    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 at 9:52

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.