Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/path-matcher-segment-wildcard.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/shared/src/pathMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { pathToRegexp } from './pathToRegexp';
import type { Autocomplete } from './types';

export type WithPathPatternWildcard<T = string> = `${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 = string> = T extends '/' ? '/:path*' : `${T & string}/:path*`;
export type PathPattern = Autocomplete<WithPathPatternWildcard>;
export type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;

Expand Down
Loading