Tiger Router v2.0.0 π―
Complete rewrite of tiger-router with TypeScript, framework-agnostic core, and modern React bindings.
π Highlights
- β Full TypeScript migration
- β Framework-agnostic core (history + route matcher)
- β
Modern React bindings (
Router,Route,Link) - β
New hooks:
useLocation,useNavigate,useParams,useRouteMatch - β Tiny bundle (~4.8 kB packed)
- β ESM + CJS + types ready for modern toolchains
π§ TypeScript Migration
- Rewritten entire codebase in TypeScript
- Enabled strict mode for safer typings
- Automatic
.d.tsgeneration withtsup tsconfig.jsonoptimized for library usage
Result: first-class DX for TS projects, with full IntelliSense and type safety.
π§© Framework-Agnostic Core
New core modules under src/core/:
-
history.ts- Minimal history wrapper
historyandhashmodes- Subscription mechanism for location changes
-
matcher.ts- Simple route pattern matching (
/users/:id) - Parameter extraction:
{ id: "123" } - Used internally by React bindings and hooks
- Simple route pattern matching (
This keeps the router small and opens the door for potential non-React bindings in the future.
βοΈ Modern React Bindings
New React layer under src/react/:
-
<Router>- Provides routing context (location, navigate, params)
- Supports
mode="history" | "hash"(default:history)
-
<Route>- Renders when
pathmatches current location - Uses
elementprop orchildren
- Renders when
-
<Link>- SPA navigation component
- Prevents full page reloads
- Uses router
navigateunder the hood
Hooks
useLocation()β get current locationuseNavigate()β programmatic navigationuseParams()β access route parametersuseRouteMatch(path)β check if path matches current location
ποΈ Build System
- Switched to tsup for bundling
- Outputs:
dist/index.js(ESM)dist/index.cjs(CJS)dist/index.d.ts/dist/index.d.cts
package.jsonconfigured with:"main","module","types"and"exports""files"whitelisted to keep package clean
preparescript now runsnpm run build
Result: clean, modern, tree-shakeable bundle.
π§ͺ Testing & Quality
- Added tests for:
- Core matcher
- Core history navigation
- React Router integration
- Commands:
npm testβ all tests passingnpx tsc --noEmitβ no type errorsnpm run buildβ successful
An integration test project was also used to verify:
- Installation from packed tarball
- TypeScript compatibility
- React 18 usage
- No peer dependency warnings
π₯ Breaking Changes
If you were using v1, please note:
<Router>no longer accepts aroutesprop<Route>now uses:element(preferred) orchildren
instead of older patterns
- Components should now use
useParams()hook
instead of receivingrouteParamsvia props