The URL API, supported in all modern browsers, provides a way to parse and manipulate URLs. Understanding the parts of a URL
With modern JavaScript, we can parse URLs and extract these different parts as needed. In older browsers, before the URL API was available, one way that developers parsed URLs was by using an element.
If you’re interested in the value of a particular parameter in the query string, you can use its get method to get the parameter by its name.
Let’s look at a simple case first:
If you call the URL constructor with a relative URL and specify an invalid or incomplete URL for the base URL, you’ll get an error.
Using the URLPattern API to match patterns within URLs can be useful for things like client-side routing in a single-page application (SPA).
The URL API is a versatile interface for constructing, validating, and manipulating URLs in JavaScript.
By using a URLSearchParams object, you can build a query string without worrying about string concatenation or encoding special characters.
Creating relative URLs - Normally, the argument to the URL constructor will throw an error if it’s not a full, valid URL.
You might be familiar with the window.location object, which represents the current page’s URL.