Lightweight and fast router for JavaScript.
[!NOTE]
Radix3 migrated to Rou3! See #108 for notes and radix3 branch for legacy codebase.
undefinedInstall:undefined
# ✨ Auto-detect
npx nypm install rou3
# npm
npm install rou3
# yarn
yarn add rou3
# pnpm
pnpm install rou3
# bun
bun install rou3
undefinedImport:undefined
undefinedESM (Node.js, Bun)
import {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} from "rou3";
undefinedCommonJS (Legacy Node.js)
const {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} = require("rou3");
undefinedCDN (Deno, Bun and Browsers)
import {
createRouter,
addRoute,
findRoute,
removeRoute,
findAllRoutes,
} from "https://esm.sh/rou3";
undefinedCreate a router instance and insert routes:undefined
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",
});
undefinedMatch route to access matched data:undefined
// 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", "/");
Published under the MIT license.
Made by @pi0 and community 💛
🤖 auto updated with automd
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.