page.js
Micro client-side router inspired by the Express router
A tiny client-side router for single-page apps that swaps content on link clicks or URL changes without full page reloads.
Plain-English Explanation: page.js
This is a tiny routing library for single-page web applications—basically, a tool that lets you build websites where different "pages" load without refreshing the browser. When someone clicks a link or types a URL, the router figures out which piece of code should run and handles it, all without the clunky full-page reload.
The library works by listening for when someone clicks a link or uses the browser's back button. When that happens, it matches the URL against a list of routes you've defined—similar to how a restaurant might route orders to different kitchen stations. Each route can have one or more functions attached to it that handle what actually happens (fetch data, show content, update the page, etc.). You can pass information through the URL like /user/john and access that username in your code. It also plays nicely with the browser's history, so the back button works like users expect.
This is useful for anyone building interactive web apps without a heavy framework. If you're making a dashboard, a project management tool, a photo gallery, or anything where you want smooth transitions between sections without page reloads, this library handles the plumbing. It's designed to be minimal and fast—roughly a few kilobytes—so it doesn't add bloat to your site. The API is intentionally similar to Express (a popular server-side framework), so developers familiar with Express find it comfortable to work with.
One helpful aspect is that you can chain multiple functions together for a single route—for example, run a "load user data" function first, then a "display user profile" function. This makes it easy to reuse logic across different routes. The README includes several working examples (basic routing, user profiles, pagination, transitions between pages) that show common patterns.
Where it fits
- Add smooth, reload-free page transitions to a dashboard or project management tool.
- Define URL routes like /user/john and read the username parameter inside a route handler.
- Chain multiple functions on one route, such as loading user data before rendering a profile page.
- Build a lightweight single-page app without pulling in a heavy framework.