How to get URL parameter in Salesforce community page lightning component?

URL

https://yourcommunityurl.my.salesforce.com/communityname?id=abc&str=test

Controller Code:

var idParam = helper.getJsonFromUrl().id;//will get abc as id
var strParam = helper.getJsonFromUrl().str;//will get test as str

Helper Code:

({
getJsonFromUrl : function () {
        var query = location.search.substr(1);
        var result = {};
        query.split("&").forEach(function(part) {
            var item = part.split("=");
            result[item[0]] = decodeURIComponent(item[1]);
        });
        return result;
    }
})

No comments:

Post a Comment