Build Your Own Router with URLPattern()

Build‑your‑own website switcher sparks a fight—Do we even need it

TLDR: URLPattern now works in all browsers, letting developers match website addresses and build tiny “routers” without big libraries. Comments split: some cheer a simple, native tool; others say it’s unnecessary because routing is easy and JavaScript already handles it—welcome convenience vs reinvented wheel.

URLPattern just landed in every browser, and one dev showed how to build a make‑your‑own website “router” that swaps views based on the address bar. Simple idea, big drama: the comments immediately split into Team Finally vs Team Why Bother.

On the skeptic side, tinco wonders why this needed standardizing at all, saying JavaScript could already do it. jazzypants shrugged, asking if this is really easier than just matching paths yourself. Meanwhile, pscanf came in hot, calling react‑router “insanity” and insisting routing isn’t hard—just pick a route and render the right piece.

The jokes flew too: teddyh deadpanned, “SPA router, not IP router,” as folks argued over the spicy detail that “/cat” is not the same as “/cat/.” Cue slash memes, pedant battles, and cheers for wildcards that finally let “/cat/other‑things” pass.

Supporters like jauntywundrkind say the platform should handle boring stuff, and a native API could even be faster. Critics think it’s reinventing a wheel they already built. The vibe: half eye‑roll, half fist‑pump. But if you’ve ever wanted to match “/posts/123” without dragging in a giant library, URLPattern is the shiny new tool—whether you call it useful or overkill.

Key Points

  • URLPattern is presented as available in all major browsers and suitable for SPA routing.
  • Exact path matching distinguishes between "/cat" and "/cat/", requiring explicit handling.
  • An optional trailing slash can be matched using a grouped slash pattern: "{/}?".
  • A wildcard "?*" allows patterns to accept additional segments after a base route.
  • A sequential router configuration maps URLPattern instances to component tags, rendering the first match and leaving 404 handling as a TODO.

Hottest takes

"SPA router, not IP router" — teddyh
"routing in a single page application is just not that hard of a problem" — pscanf
"I wonder why this was standardized" — tinco
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.