https://github.com/unjs/rou3
🌳 Lightweight and fast rou(ter) for JavaScript
https://github.com/unjs/rou3
Last synced: about 2 months ago
JSON representation
🌳 Lightweight and fast rou(ter) for JavaScript
- Host: GitHub
- URL: https://github.com/unjs/rou3
- Owner: unjs
- License: mit
- Created: 2021-11-24T23:02:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-31T13:45:13.000Z (about 2 months ago)
- Last Synced: 2025-03-31T14:52:35.345Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 860 KB
- Stars: 532
- Watchers: 7
- Forks: 21
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 🌳 rou3
[](https://npmjs.com/package/rou3)
[](https://npmjs.com/package/rou3)
[](https://bundlejs.com/?q=rou3)
[](https://codecov.io/gh/unjs/rou3)Lightweight and fast router for JavaScript.
> [!NOTE]
> Radix3 migrated to Rou3! See [#108](https://github.com/unjs/radix3/issues/108) for notes and [radix3 branch](https://github.com/unjs/rou3/tree/radix3) for legacy codebase.## Usage
**Install:**
```sh
# ✨ Auto-detect
npx nypm install rou3# npm
npm install rou3# yarn
yarn add rou3# pnpm
pnpm install rou3# bun
bun install rou3
```**Import:**
**ESM** (Node.js, Bun)
```js
import {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} from "rou3";
```**CommonJS** (Legacy Node.js)
```js
const {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} = require("rou3");
```**CDN** (Deno, Bun and Browsers)
```js
import {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} from "https://esm.sh/rou3";
```**Create a router instance and insert routes:**
```js
import { createRouter, addRoute } from "rou3";const router = createRouter(/* options */);
addRoute(router, "GET", "/path", { payload: "this path" });
addRoute(router, "POST", "/path/:name", { payload: "named route" });
addRoute(router, "GET", "/path/foo/**", { payload: "wildcard route" });
addRoute(router, "GET", "/path/foo/**:name", {
payload: "named wildcard route",
});
```**Match route to access matched data:**
```js
// Returns { payload: 'this path' }
findRoute(router, "GET", "/path");// Returns { payload: 'named route', params: { name: 'fooval' } }
findRoute(router, "POST", "/path/fooval");// Returns { payload: 'wildcard route' }
findRoute(router, "GET", "/path/foo/bar/baz");// Returns undefined (no route matched for/)
findRoute(router, "GET", "/");
```## License
Published under the [MIT](https://github.com/unjs/rou3/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/rou3/graphs/contributors) 💛
![]()
---
_🤖 auto updated with [automd](https://automd.unjs.io)_