Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-route-matcher

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NextJS Router Matcher

Want to use nextjs-style routes without the next module? This module lets you easily match routes. This code was adapted directly from the NextJS implementation.

Installation

yarn add next-route-matcher

Usage

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"],
//   },
// }

FAQs

Package last updated on 15 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc