# next-route-matcher

> Want to use [nextjs-style routes](https://nextjs.org/docs/routing/dynamic-routes) without the [next module](https://github.com/vercel/next.js/)? This module lets you easily match routes. This code was adapted directly from the NextJS implementation.

Latest version **1.0.2** (published 2024-01-15) · 0 weekly downloads

## Install

```sh
npm install next-route-matcher
pnpm add next-route-matcher
yarn add next-route-matcher
bun add next-route-matcher
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-01-15 |
| First published | 2022-07-20 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | seveibar |

## Links

- npm: https://www.npmjs.com/package/next-route-matcher
- Repository: https://github.com/seamapi/next-route-matcher
- Homepage: https://github.com/seamapi/next-route-matcher#readme
- Issues: https://github.com/seamapi/next-route-matcher/issues
- npm.io page: https://npm.io/package/next-route-matcher

## Recent versions

- 1.0.2 (latest) — 2024-01-15
- 1.0.1 — 2022-12-18
- 1.0.0 — 2022-07-20

## README

# NextJS Router Matcher

Want to use [nextjs-style routes](https://nextjs.org/docs/routing/dynamic-routes)
without the [next module](https://github.com/vercel/next.js/)? This module lets
you easily match routes. This code was adapted directly from the NextJS
implementation.

## Installation

```bash
yarn add next-route-matcher
```

## Usage

```ts
import nextRouteMatcher from "next-route-matcher"

const routeMatcher = nextRouteMatcher([
  "/health",
  "/api/nested",
  "/api/items/[item_name]",
  "/api/[someslug]/list",
  "/api/[slug1]/deepnest/[slug2]/image.png",
  "/api/[someslug]/greetings/[...anything]",
])

routeMatcher("/health")
// {
//   matchedRoute: "/health",
//   routeParams: {},
// }

routeMatcher("/api/nested")
// {
//   matchedRoute: "/api/nested",
//   routeParams: {},
// }

routeMatcher("/api/items/someitem")
// {
//   matchedRoute: "/api/items/[item_name]",
//   routeParams: { item_name: "someitem" },
// }

routeMatcher("/api/someslug/list")
// {
//   matchedRoute: "/api/[someslug]/list",
//   routeParams: { someslug: "someslug" },
// }

routeMatcher("/api/slug1/deepnest/slug2/image.png")
// {
//   matchedRoute: "/api/[slug1]/deepnest/[slug2]/image.png",
//   routeParams: {
//     slug1: "slug1"
//     slug2: "slug2",
//   }
// },
routeMatcher("/api/someslug/greetings/something/somethingelse.txt")
// {
//   matchedRoute: "/api/[someslug]/greetings/[...anything]"
//   routeParams: {
//     someslug: "someslug",
//     anything: ["something", "somethingelse.txt"],
//   },
// }
```

---
_Source: https://npm.io/package/next-route-matcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
