Skip to content

Commit d7b8d74

Browse files
nicohrubecclaude
andcommitted
ref: Remove splat route handling to simplify matching logic
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 762519b commit d7b8d74

2 files changed

Lines changed: 1 addition & 26 deletions

File tree

packages/tanstackstart-react/src/server/routeParametrization.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ function patternToRegex(pattern: string): RegExp {
1212
const segments = pattern
1313
.split('/')
1414
.map(segment => {
15-
if (segment === '$') {
16-
return '.+';
17-
}
1815
if (segment.startsWith('$')) {
1916
return '[^/]+';
2017
}
@@ -28,7 +25,7 @@ function patternToRegex(pattern: string): RegExp {
2825
* Matches a URL pathname against a list of TanStack Start route patterns.
2926
* Patterns use `$param` syntax for dynamic segments (e.g., `/users/$id`).
3027
*
31-
* Patterns are sorted by specificity: more segments first, static before dynamic, splat last.
28+
* Patterns are sorted by specificity: more segments first, static before dynamic.
3229
*/
3330
export function matchUrlToRoutePattern(pathname: string, patterns: string[]): string | undefined {
3431
const sorted = [...patterns].sort((a, b) => {
@@ -37,11 +34,6 @@ export function matchUrlToRoutePattern(pathname: string, patterns: string[]): st
3734
if (bSegments.length !== aSegments.length) {
3835
return bSegments.length - aSegments.length;
3936
}
40-
const aSplat = aSegments.filter(s => s === '$').length;
41-
const bSplat = bSegments.filter(s => s === '$').length;
42-
if (aSplat !== bSplat) {
43-
return aSplat - bSplat;
44-
}
4537
const aDynamic = aSegments.filter(s => s.startsWith('$')).length;
4638
const bDynamic = bSegments.filter(s => s.startsWith('$')).length;
4739
return aDynamic - bDynamic;

packages/tanstackstart-react/test/server/routeParametrization.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,4 @@ describe('matchUrlToRoutePattern', () => {
3737
const patternsNested = ['/users/$id', '/users/$id/profile'];
3838
expect(matchUrlToRoutePattern('/users/123/profile', patternsNested)).toBe('/users/$id/profile');
3939
});
40-
41-
it('matches splat/catch-all routes across multiple segments', () => {
42-
const patternsWithSplat = ['/', '/files/$'];
43-
expect(matchUrlToRoutePattern('/files/a/b/c', patternsWithSplat)).toBe('/files/$');
44-
expect(matchUrlToRoutePattern('/files/readme.txt', patternsWithSplat)).toBe('/files/$');
45-
});
46-
47-
it('prefers specific routes over splat routes', () => {
48-
const patternsWithSplat = ['/files/$', '/files/upload'];
49-
expect(matchUrlToRoutePattern('/files/upload', patternsWithSplat)).toBe('/files/upload');
50-
expect(matchUrlToRoutePattern('/files/a/b', patternsWithSplat)).toBe('/files/$');
51-
});
52-
53-
it('prefers named param routes over splat routes with same segment count', () => {
54-
const patternsWithBoth = ['/files/$', '/files/$name'];
55-
expect(matchUrlToRoutePattern('/files/readme.txt', patternsWithBoth)).toBe('/files/$name');
56-
});
5740
});

0 commit comments

Comments
 (0)