Skip to content

Commit 42aee20

Browse files
author
Jacek
committed
fix(shared): address path wildcard review comments
1 parent 6065a89 commit 42aee20

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎packages/shared/src/pathMatcher.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ import type { Autocomplete } from './types';
66
* (e.g. `/dashboard(.*)` matches `/dashboardxyz`).
77
*/
88
export type WithPathPatternWildcard<T = string> = `${T & string}(.*)`;
9-
// Suggests the `:path*` subtree form (e.g. `/dashboard/:path*`), which matches on
10-
// path-segment boundaries. `/` is special-cased to `/:path*` to avoid a malformed `//:path*`.
11-
export type WithPathSegmentWildcard<T = string> = T extends '/' ? '/:path*' : `${T & string}/:path*`;
9+
10+
type StripTrailingSlash<T extends string> = T extends '/'
11+
? T
12+
: T extends `${infer Prefix}/`
13+
? StripTrailingSlash<Prefix>
14+
: T;
15+
16+
/**
17+
* Suggests the `:path*` subtree form (e.g. `/dashboard/:path*`), which matches on
18+
* path-segment boundaries. `/` is special-cased to `/:path*` to avoid a malformed `//:path*`.
19+
*/
20+
export type WithPathSegmentWildcard<T = string> = T extends '/'
21+
? '/:path*'
22+
: `${StripTrailingSlash<T & string>}/:path*`;
1223
export type PathPattern = Autocomplete<WithPathSegmentWildcard>;
1324
export type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;
1425

0 commit comments

Comments
 (0)