{"id":11961,"library":"route-recognizer","title":"Lightweight Route Recognizer","description":"route-recognizer is a compact JavaScript library (under 2KB) designed solely for matching paths against a set of registered routes. It functions as a low-level primitive for more comprehensive routing systems, such as `router.js`, which was notably used by Ember.js. Currently at version 0.3.4, last published in 2018, the library offers stable functionality for static, dynamic (e.g., `:id`), and wildcard (e.g., `*path`) segments. Its core differentiator is its minimalistic approach, focusing exclusively on route recognition and parameter extraction without handling routing logic, history, or view rendering. The package ships with TypeScript types, but its development status appears to be unmaintained given the last commit and release dates.","status":"abandoned","version":"0.3.4","language":"javascript","source_language":"en","source_url":"https://github.com/tildeio/route-recognizer","tags":["javascript","typescript"],"install":[{"cmd":"npm install route-recognizer","lang":"bash","label":"npm"},{"cmd":"yarn add route-recognizer","lang":"bash","label":"yarn"},{"cmd":"pnpm add route-recognizer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library uses a default export for its main class, not named export for the class itself.","wrong":"import { RouteRecognizer } from 'route-recognizer';","symbol":"RouteRecognizer","correct":"import RouteRecognizer from 'route-recognizer';"},{"note":"CommonJS usage aligns with the default export pattern; directly assigning the require result to the class name.","wrong":"const { RouteRecognizer } = require('route-recognizer');","symbol":"RouteRecognizer (CommonJS)","correct":"const RouteRecognizer = require('route-recognizer');"},{"note":"For TypeScript, import the type explicitly if only type-checking is needed, although direct value import also works for both value and type.","symbol":"RouteRecognizer (Type)","correct":"import type { RouteRecognizer } from 'route-recognizer';"}],"quickstart":{"code":"import RouteRecognizer from 'route-recognizer';\n\nconst router = new RouteRecognizer();\n\nconst postsHandler = (params) => `Handling posts with params: ${JSON.stringify(params)}`;\nconst singlePostHandler = (params) => `Handling single post with ID: ${params.id}`; \nconst adminHandler = () => `Admin section accessed`;\nconst pageHandler = (params) => `Serving page: ${params.path}`;\n\nrouter.add([{ path: \"/posts\", handler: postsHandler }], { as: \"allPosts\" });\nrouter.add([{ path: \"/posts/:id\", handler: singlePostHandler }], { as: \"singlePost\" });\nrouter.add([ { path: \"/admin\", handler: adminHandler }, { path: \"/posts\", handler: postsHandler } ], { as: \"adminPosts\" });\nrouter.add([{ path: \"/pages/*path\", handler: pageHandler }], { as: \"catchAllPages\" });\n\nlet result = router.recognize(\"/posts\");\nconsole.log(\"Recognizing /posts:\", result?.[0]?.handler(result?.[0]?.params));\n\nresult = router.recognize(\"/posts/123\");\nconsole.log(\"Recognizing /posts/123:\", result?.[0]?.handler(result?.[0]?.params));\n\nresult = router.recognize(\"/admin/posts\");\nconsole.log(\"Recognizing /admin/posts:\", result?.[1]?.handler(result?.[1]?.params));\n\nresult = router.recognize(\"/pages/about/us\");\nconsole.log(\"Recognizing /pages/about/us:\", result?.[0]?.handler(result?.[0]?.params));","lang":"typescript","description":"This quickstart demonstrates how to instantiate RouteRecognizer, add various route patterns including dynamic and star segments, and then use the `recognize` method to match paths and retrieve associated handlers and parameters."},"warnings":[{"fix":"Always test routes with ambiguous paths to ensure they resolve as intended. Structure route definitions from most specific to least specific, if possible, to align with the recognizer's internal sorting logic.","message":"When multiple routes match a given path, `route-recognizer` prioritizes routes based on specificity: explicit static paths are preferred over dynamic segments, and fewer dynamic segments are preferred. If segments are identical, the number of handlers and then definition order are used as tiebreakers. This behavior might be unexpected if a user anticipates a different matching priority (e.g., first-defined wins).","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider alternatives for new projects. For existing projects, be aware that security updates or bug fixes are unlikely. Test thoroughly in modern environments.","message":"The `route-recognizer` package has not seen active development since its last release (0.3.4 in 2018), and its GitHub repository shows no recent commits. Development dependencies mentioned in the README (like Bower and Travis CI) are largely outdated. This indicates the library is no longer actively maintained and may not be compatible with newer JavaScript features or build environments without additional polyfills or transpilation.","severity":"deprecated","affected_versions":">=0.3.4"},{"fix":"Use dynamic segments (`:param`) for single path segments and star segments (`*param`) for multi-segment or trailing path matches.","message":"Dynamic segments (e.g., `:id`) in `route-recognizer` match any character *except* a forward slash (`/`). This means a dynamic segment will not consume subsequent path segments. For matching multiple path segments, a star segment (e.g., `*path`) should be used instead.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For ES Modules: `import RouteRecognizer from 'route-recognizer';` For CommonJS: `const RouteRecognizer = require('route-recognizer');`","cause":"The `RouteRecognizer` class was not correctly imported or required before use.","error":"ReferenceError: RouteRecognizer is not defined"},{"fix":"Ensure `RouteRecognizer` is instantiated correctly: `const router = new RouteRecognizer();`","cause":"The `router` variable is not an instance of `RouteRecognizer`. This usually happens if `new` keyword is omitted during instantiation.","error":"TypeError: router.add is not a function"},{"fix":"This specific error is unlikely to come directly from `route-recognizer` as it primarily deals with `recognize`. If encountered in a surrounding router, ensure the route name used for generation matches a registered route. For `route-recognizer` directly, verify that you are not trying to generate routes by name, but rather using `recognize` with a path string.","cause":"This error occurs when attempting to generate a URL by name (if the library supported it, which `route-recognizer` doesn't directly expose but a higher-level router built on top might) or if a named route was not registered. `route-recognizer` itself does not have a public API for generating paths by name; names are for identification within its internal structure or for systems built on top. The core library only recognizes paths.","error":"Error: There are no routes named `routeName`"}],"ecosystem":"npm"}