Skip to main content

Built and signed on GitHub Actions

A lightweight and flexible routing library designed for handling complex routes with support for path parameters, wildcard routes, and optional segments

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
4 months ago (0.3.1)
class Router

Represents a router that handles routing and matching of URL paths to handler functions.

Constructors

new
Router(dividers?: string[])

Creates a new instance of the Constructor class.

Type Parameters

Handler = DefaultHandler

Properties

Returns the string representation of the current object. The string representation is obtained by calling the toString method of the root property.

private
root: RouteNode<Handler>

Methods

group(
path: string,
cb: (router: Router<Handler>) => void,
): void

Applies a group of routes to the current router.

match(path: string): { handler: Handler; params: Params; } | null

Matches a given path against the routes defined in the router.

on(
path: string,
handler: Handler,
): void

Adds a handler function to the specified path.

private
splitPath(path: string)

Add Package

deno add jsr:@cjvnjde/nano-router

Import symbol

import { Router } from "@cjvnjde/nano-router";

---- OR ----

Import directly with a jsr specifier

import { Router } from "jsr:@cjvnjde/nano-router";

Add Package

npx jsr add @cjvnjde/nano-router

Import symbol

import { Router } from "@cjvnjde/nano-router";

Add Package

yarn dlx jsr add @cjvnjde/nano-router

Import symbol

import { Router } from "@cjvnjde/nano-router";

Add Package

pnpm dlx jsr add @cjvnjde/nano-router

Import symbol

import { Router } from "@cjvnjde/nano-router";

Add Package

bunx jsr add @cjvnjde/nano-router

Import symbol

import { Router } from "@cjvnjde/nano-router";