Access URL params
--
URL parameters or sometimes called query strings is a concept of structuring additional information in the URL. The parameters follow a “?” and multiple parameters are separated by the ‘&’.
These parameters are great ways to include additional data that is readily available and accessible at all times. For example, if our url looked something like this
https://www.videostreaming.com/watch?cat_memes
Being able to target the keyword from the URL could be very useful in certain cases so quickly let’s see how to do that.
const search = window.location.search;
console.log(search);
window.location.search grabs the url search params which is everything after the ‘/’ or main domain. After saying the params to a variable we can then parse the variable with the urlParams.get() method.
const watch = search.get('watch');
console.log(watch);
If we do this correctly we will get access to a string called “cat_memes” under the variable watch.