Wednesday, August 7, 2019

How to get URL parameters in Lighting web componet(lwc)

This post explains how to read URL parameters in Lighting Web Components(lwc)

In this demo, I am using static URL if you want to get URL dynamically
Use window.location.href

Example URL:
http://www.example.com/index.php?id=1&image=awesome.jpg
// if you have Dynamic URL Use (window.location.href)
let testURL = 'http://www.example.com/index.php?id=1&image=awesome.jpg';

let newURL = new URL(testURL).searchParams;

console.log('id ===> '+newURL.get('id'));
console.log('image ====> '+newURL.get('image'));
Output


1 comment: