react-server675fbba4
react-servercommitb7f5f45a9033

feat: enhanced router (#372)

A major evolution of the @lazarv/react-server router, introducing a fully typed routing system, a resource abstraction for data management, scroll restoration, and client-only page support in the file router. This is a foundational change that brings the router closer to feature parity with — and in several areas beyond — framework-level routers like Next.js App Router and TanStack Router.

  • Typed Router — Define routes with full TypeScript type safety for path params, search params, and navigation. Includes path/search param parsers, encoders/decoders, and validator schema support (single or multiple validators). New Route, Link, and hook APIs (useParams, useSearchParams, useNavigate) are fully type-aware.
  • Resources — A new @lazarv/react-server/resources export introducing a data resource primitive. Resources can be defined as client-side, server-side, or both, with file-system conventions (.resource.ts) in the file router. Supports CRUD-style operations with automatic cache integration.
  • Scroll Restoration — Comprehensive scroll restoration system supporting both auto and manual modes. Tracks scroll positions across navigations with configurable selectors, smooth scrolling, and hash fragment support. Fully client-driven with no server round-trips.
  • Client-Only Pages — The file router now supports client-only pages that render entirely on the client without a server component counterpart. Includes proper loading/fallback component support for client-only routes.
  • Virtual Routes — Programmatically define routes in react-server.config.mjs without corresponding files on disk. Enables dynamic route registration from plugins or configuration.
  • Scoped Fallback Routes — Fallback (catch-all) routes can now be scoped to specific route subtrees rather than only matching globally.
  • Functional Search Param UpdaterssetSearchParams now accepts a function (prev) => next for atomic updates based on current state, in addition to the existing object form.
Author
Viktor Lázár <lazarv1982@gmail.com>
Date
Commit
b7f5f45a9033b8ed754cff40f01290d03a0aa079
181 files changed+17507 -1518