Back to articles
One regex to match them all

One regex to match them all

via Dev.to WebdevVadim Ferderer

Last year I was building a single-page app with SvelteKit. Nothing fancy—a handful of views, client-side navigation, and zero need for server-side rendering. Should be simple, right? It wasn't. SvelteKit assumes you want SSR. It assumes you want its file-based routing. It assumes you want its data-loading conventions. I didn't want any of that. I just wanted a URL to map to a component. So I started looking at alternatives. Router Size (min+gz) Framework-agnostic? Nested routes? Single-regex matching? TanStack Router ~44 kB No (React) Yes No Vue Router ~28 kB No (Vue) Yes No navigo ~9 kB Yes No No wouter ~3.5 kB No (React) Limited No I looked at this and thought, why does URL matching require 44 kB? The single regex trick Here's the core insight behind Texivia: most routers store routes in an array or a tree and iterate through them on every navigation. You have 30 routes? That's up to 30 pattern matches per URL change. It's O(n). Texivia takes a different approach. When you define you

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles