The URLPattern API is currently available in Chrome 93 and later behind a flag.
- Download Chrome (Android, Desktop).
- Navigate to
chrome://flags
and enableExperimental Web Platform features
. - Visit a page that uses
URLPattern
, such as the demo on glitch.
Here is an example of how to use the API:
const pattern = new URLPattern({ pathname: '/:product/index.html' });
const result = pattern.exec(someURL);
if (result) {
handleProduct(result.pathname.groups.product);
}
More code examples can be found in the URLPattern documentation.