Skip to content
/ rou3 Public

🌳 Lightweight and fast rou(ter) for JavaScript

License

Notifications You must be signed in to change notification settings

h3js/rou3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6cf82d7 Β· Apr 17, 2025
Apr 17, 2025
Apr 17, 2025
Apr 17, 2025
Nov 24, 2021
Jul 9, 2024
Oct 4, 2023
Apr 17, 2025
Nov 15, 2022
Apr 17, 2025
Apr 17, 2025
Jul 5, 2024
Apr 17, 2025
Apr 17, 2025
Oct 4, 2023
Jul 8, 2024
Jul 7, 2024

Repository files navigation

🌳 rou3

npm version npm downloads bundle size codecov

Lightweight and fast router for JavaScript.

Note

Radix3 migrated to Rou3! See #108 for notes and radix3 branch for legacy codebase.

Usage

Install:

# ✨ Auto-detect
npx nypm install rou3

Import:

ESM (Node.js, Bun, Deno)

import {
  createRouter,
  addRoute,
  findRoute,
  removeRoute,
  findAllRoutes,
} from "rou3";

CDN (Deno, Bun and Browsers)

import {
  createRouter,
  addRoute,
  findRoute,
  removeRoute,
  findAllRoutes,
} from "https://esm.sh/rou3";

Create a router instance and insert routes:

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:

// 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 license. Made by @pi0 and community πŸ’›


πŸ€– auto updated with automd