How It Works
Ufbr bridges Vite’s build-time module discovery with fast client-side SPA routing. At its core, ufbr is powered by the Ziko.js router engine, leveraging its lightweight, framework-agnostic path-matching logic to drive client-side navigation across React, Preact, Solid, Svelte, Vue, Van, and Ziko.
The Core Pipeline
Section titled “The Core Pipeline”When you initialize ufbr, it processes your project files through a 4-stage pipeline:
-
Vite Glob Parsing
ufbrconsumes Vite’simport.meta.glob()utility to discover your pages at build time. When you pass your page glob tocreateFileBasedRouter:createFileBasedRouter({pages: import.meta.glob('./pages/**/*.[jsx,js]'),target: document.body})Vite generates an object mapping file paths to dynamic import functions:
// Raw Vite Glob Object{'./pages/index.jsx': () => import('./pages/index.jsx'),'./pages/about.jsx': () => import('./pages/about.jsx'),'./pages/blog/[id].jsx': () => import('./pages/blog/[id].jsx'),'./pages/[...slug].jsx': () => import('./pages/[...slug].jsx')} -
Route Manifest Normalization
ufbriterates over the glob object, stripping the base directory (./pages/) and file extensions to convert filesystem syntax into standardized URL patterns.File Path Transformed Route|-- ./pages/index.jsx --> /|-- ./pages/about.jsx --> /about|-- ./pages/blog/index.jsx --> /blog|-- ./pages/blog/[id].jsx --> /blog/:id|-- ./pages/[...slug].jsx --> /* -
Powered by Ziko.js Router
Once normalized, these route definitions are registered directly into the Ziko.js routing engine. Instead of reinventing routing logic for every framework,
ufbrrelies on Ziko’s core to handle fast pattern matching and parameter extraction. -
Framework Adapter Render
The final stage triggers when a URL change occurs. The Ziko router identifies the match and extracts any parameters. The framework adapter (e.g.,
ufbr/preactorufbr/react) resolves the dynamic import and mounts the resulting component tree directly into your specified DOM target, all without a full page refresh.