route-pattern@0.21.0
Breaking Changes📦 remixView on GitHub →
⚠ 3 breaking✨ 5 features🐛 2 fixes🔧 12 symbols
Summary
This release introduces significant API modularization via subpath exports to reduce client-side bundle size and removes the custom sorting parameter from matching functions. Several bugs related to URL matching and parameter encoding have also been resolved.
⚠️ Breaking Changes
- The `compareFn` parameter has been removed from `match` and `matchAll` methods. Matches now always sort by specificity (most specific first). To customize sorting, sort the result of `matchAll` manually using specificity utilities.
- The package API has been modularized, replacing the monolithic `RoutePattern` class with specialized subpath exports for different functionalities (e.g., `remix/route-pattern/href`, `remix/route-pattern/match`, `remix/route-pattern/join`). The core `RoutePattern` is now a thin wrapper around parsed patterns with a static `parse` method.
- The `ArrayMatcher` and `TrieMatcher` classes have been removed and replaced by `createMultiMatcher`, which is now always backed by trie-based matching. Use `createMatcher` for matching a single pattern with type-safe params.
Migration Steps
- If you were using `matcher.matchAll(url, Specificity.ascending)`, change it to `matcher.matchAll(url).sort(Specificity.ascending)`.
- Update imports to use the new modular subpath exports, for example, import matching logic from `remix/route-pattern/match` instead of the default export.
- Replace usage of `ArrayMatcher` or `TrieMatcher` with `createMultiMatcher`.
- If matching a single pattern and requiring type-safe params, use `createMatcher` instead of older methods.
✨ New Features
- New modular APIs introduced via subpath exports (`remix/route-pattern/href`, `remix/route-pattern/match`, `remix/route-pattern/join`) to reduce client-side JavaScript bloat by only shipping necessary code.
- Href parameters are now encoded to prevent pathname params from injecting URL path, dot segment, query, or hash syntax.
- Wildcard pathname params now preserve slash-separated structure while encoding each segment.
- Hostname params are normalized or rejected if they attempt to inject URL authority, path, query, or hash syntax.
- Matchers now decode generated pathname params, allowing reserved characters like `/`, `?`, and `#` to round-trip as param content.
🐛 Bug Fixes
- Fixed matchers to correctly match origin-less patterns (e.g., `/`, `/about`) against URLs that include an explicit port (e.g., `http://localhost:44199/`).
- Prevented partial matches for variables and wildcards in pathnames, ensuring patterns only match when they cover the entire segment.