Skip to content

URLPattern

Medium — good to knowFrontend

ELI5 - The Vibe Check

URLPattern is the browser's built in way to match and parse URLs against a pattern, like /users/:id, without reaching for a routing library or writing your own regex from scratch. Routers have been reinventing this exact wheel for years, and now it just lives in the platform.

Real Talk

URLPattern is a browser API for matching URLs against a pattern syntax similar to path-to-regexp, extracting named groups from the pathname, search params, hash, and more. It is used internally by browser features like Service Worker routing and is increasingly used by routing libraries instead of shipping their own pattern matching code.

Show Me The Code

const pattern = new URLPattern({ pathname: '/users/:id' });
const match = pattern.exec('https://site.com/users/42');
console.log(match.pathname.groups.id); // '42'

When You'll Hear This

"We swapped our hand rolled route matcher for URLPattern and deleted a dependency." / "URLPattern gives you named groups straight out of the match, no extra parsing needed."

Made with passive-aggressive love by manoga.digital. Powered by Claude.