wouter is a minimalist routing library for React and Preact, only about 2.1KB minified, compared with 18.7KB for React Router. It supports React and Preact, requires no top-level <Router /> component (it is fully optional), and mimics React Router's best practices by providing familiar Route, Link, Switch, and Redirect components. It also provides a Hook-based API (useLocation, useRoute, useRouter, etc.) for finer-grained control (such as animations).
Main capabilities:
- Extremely lightweight: only 2.1KB gzipped, with very few dependencies.
- Dual-framework support: supports both React and Preact (Preact uses the wouter-preact package).
- Component API: <Route path={pattern} /> conditionally renders and supports nesting (nest prop); <Link href={path} /> navigates and supports asChild and a className function to determine active state; <Switch /> exclusive routing renders only the first match; <Redirect to={path} /> redirects immediately; <Router hook={hook} parser={fn} base={basepath} /> optional top-level configuration.
- Hooks API: useRoute matches a route and returns parameters; useLocation manipulates history (supports replace, state, and other parameters); useParams extracts parameters from the nearest route; useSearch gets the query string; useSearchParams manipulates URLSearchParams; useRouter accesses the global router object.
- Standalone location hooks: useBrowserLocation, useHashLocation, and memoryLocation can be used on their own, or passed to <Router> to enable features such as nesting and base path.
- Pattern matching: based on the regexparam library, supports dynamic segments, wildcards, regex paths, and more.
- Nested routing: creates a nested routing context via the nest prop, and child routes receive relative locations.
- Other features: supports base path, strict routing, relative routing, TypeScript (minimum 4.1), SSR, view transitions, animated route transitions, and more.
Usage: Install: npm i wouter (for Preact use npm i wouter-preact). Basic usage example (from the official simple demo): import { Route, Link } from "wouter"; // In a component, use <Link href="/about">About</Link> and <Route path="/about">...</Route>. For more detailed usage, refer to the official FAQ and code examples.
Use cases:
- React/Preact applications that pursue an extremely small bundle size.
- Projects that want to use Hooks for routing control.
- Projects that need to migrate from React Router but want something lighter.
- Scenarios that require nested routing, dynamic parameters, hash routing, or memory routing (testing).
Limitations:
- Designed for ES2020+; to support older browsers, node_modules must be transpiled.
- Minimum TypeScript version 4.1 (used for route parameter inference).
- Standalone location hooks do not include built-in support for nesting, base path, or route matching, and must be used with <Router>.
- The official sources do not provide specific information such as fees, pricing, or platforms.