Routing is a key piece of every web application. At its heart, routing involves taking a URL, applying some pattern matching or other app-specific log

URLPattern brings routing to the web platform

submited by
Style Pass
2021-07-22 18:30:07

Routing is a key piece of every web application. At its heart, routing involves taking a URL, applying some pattern matching or other app-specific logic to it, and then, usually, displaying web content based on the result. Routing might be implemented in a number of ways: it's sometimes code running on a server that maps a path to files on disk, or logic in a single-page app that waits for changes to the current location and creates a corresponding piece of DOM to display.

While there is no one definitive standard, web developers have gravitated towards a common syntax for expressing URL routing patterns that share a lot in common with regular expressions, but with some domain-specific additions like tokens for matching path segments. Popular server-side frameworks like Express and Ruby on Rails use this syntax (or something very close to it), and JavaScript developers can use modules like path-to-regexp or regexpparam to add that logic to their own code.

URLPattern is a proposed addition to the web platform that builds on the foundation created by these frameworks. Its goal is to standardize a routing pattern syntax, including support for wildcards, named token groups, regular expression groups, and group modifiers. URLPattern instances created with this syntax can perform common routing tasks, like matching against full URLs or a URL pathname, and returning information about the token and group matches.

Leave a Comment