Skip to content

Commit 42cecb9

Browse files
author
Jacek
committed
fix(shared): suggest :path* subtree form in createRouteMatcher path types
WithPathPatternWildcard now suggests `/dashboard/:path*` instead of `/dashboard(.*)`. The `:path*` form matches on path-segment boundaries, so it covers `/dashboard` and its subtree without also matching sibling routes like `/dashboardxyz`. Root is special-cased to `/:path*` to avoid a malformed `//:path*`. Backward compatible: the param is Autocomplete-wrapped, so existing `(.*)` patterns still type-check, and there is no runtime change.
1 parent 668b1c8 commit 42cecb9

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': patch
3+
---
4+
5+
`createRouteMatcher()` route suggestions now use the `:path*` subtree form (e.g. `/dashboard/:path*`) instead of `(.*)`. Unlike `/dashboard(.*)`, which also matches sibling routes such as `/dashboardxyz`, `/dashboard/:path*` matches only `/dashboard` and its path-segment subtree. Existing `(.*)` patterns keep working; this only changes the type-level autocomplete suggestion.

‎packages/shared/src/pathMatcher.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { pathToRegexp } from './pathToRegexp';
22
import type { Autocomplete } from './types';
33

4-
export type WithPathPatternWildcard<T = string> = `${T & string}(.*)`;
4+
// Suggests the `:path*` subtree form (e.g. `/dashboard/:path*`), which matches on
5+
// path-segment boundaries. `/` is special-cased to `/:path*` to avoid a malformed `//:path*`.
6+
export type WithPathPatternWildcard<T = string> = T extends '/' ? '/:path*' : `${T & string}/:path*`;
57
export type PathPattern = Autocomplete<WithPathPatternWildcard>;
68
export type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;
79

0 commit comments

Comments
 (0)