From 42cecb9069dd64f282bc4a1530ad425289a27217 Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 30 Jun 2026 22:21:13 -0500 Subject: [PATCH] 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. --- .changeset/path-matcher-segment-wildcard.md | 5 +++++ packages/shared/src/pathMatcher.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/path-matcher-segment-wildcard.md diff --git a/.changeset/path-matcher-segment-wildcard.md b/.changeset/path-matcher-segment-wildcard.md new file mode 100644 index 00000000000..7ad08ff33cd --- /dev/null +++ b/.changeset/path-matcher-segment-wildcard.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +`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. diff --git a/packages/shared/src/pathMatcher.ts b/packages/shared/src/pathMatcher.ts index d5e6e49f516..4ee5ccf42fc 100644 --- a/packages/shared/src/pathMatcher.ts +++ b/packages/shared/src/pathMatcher.ts @@ -1,7 +1,9 @@ import { pathToRegexp } from './pathToRegexp'; import type { Autocomplete } from './types'; -export type WithPathPatternWildcard = `${T & string}(.*)`; +// Suggests the `:path*` subtree form (e.g. `/dashboard/:path*`), which matches on +// path-segment boundaries. `/` is special-cased to `/:path*` to avoid a malformed `//:path*`. +export type WithPathPatternWildcard = T extends '/' ? '/:path*' : `${T & string}/:path*`; export type PathPattern = Autocomplete; export type PathMatcherParam = Array | RegExp | PathPattern;