Skip to content

Commit 056e0b6

Browse files
update and format
1 parent af011ad commit 056e0b6

5 files changed

Lines changed: 21 additions & 32 deletions

File tree

‎.changeset/clean-routes-match.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
'@tanstack/vue-router': minor
66
---
77

8-
Replace the experimental `skipRouteOnParseError` route option with `params.match` and `params.matchPriority` for route selection. `params.match` now gates matching with raw path params, while `params.parse` remains responsible for typed params and `params.stringify` remains responsible for URL generation.
8+
Allow `params.parse` to experimentally return `false` to skip an incoming route candidate during path matching. Thrown parse errors still surface on the selected match instead of falling through, and outgoing typed route-template links continue to use exact route lookup followed by `params.stringify` for URL generation.

‎docs/router/api/router/RouteOptionsType.md‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,10 @@ The `RouteOptions` type accepts an object with the following properties:
7979

8080
### `params.parse` method
8181

82-
- Type: `(rawParams: Record<string, string>) => TParams`
83-
- Optional
84-
- A function that will be called when this route is matched and passed the raw params from the current location and return valid parsed params. If this function throws, the route will be put into an error state and the error will be thrown during render. If this function does not throw, its return value will be used as the route's params and the return type will be inferred into the rest of the router.
85-
86-
### `params.match` method (experimental)
87-
88-
- Type: `(rawParams: Record<string, string>) => boolean`
89-
- Optional
90-
- A function that will be called during route matching and passed the raw params from the current location. If this function returns `false` or throws, the route is skipped and matching continues to other candidate routes. If this function returns `true`, the route is matched. Use `params.parse` to transform matching raw params into typed route params.
91-
92-
### `params.matchPriority` property (experimental)
93-
94-
- Type: `number`
82+
- Type: `(rawParams: Record<string, string>) => TParams | false`
9583
- Optional
96-
- Defaults to `0`
97-
- A tie-breaker for routes with `params.match` that would otherwise have the same matching priority. Higher numbers are tried first.
84+
- A function that will be called when this route is matched and passed the raw params from the current location and return valid parsed params. If this function throws, the route will be put into an error state and the error will be thrown during render. If this function returns parsed params, its return value will be used as the route's params and the return type will be inferred into the rest of the router.
85+
- Experimental: returning `false` during incoming route matching skips this route and allows matching to continue to another candidate route.
9886

9987
### `params.stringify` method
10088

‎packages/router-core/src/new-process-route-tree.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ function parseSegments<TRouteLike extends RouteLike>(
207207
const path = route.fullPath ?? route.from
208208
const length = path.length
209209
const caseSensitive = route.options?.caseSensitive ?? defaultCaseSensitive
210-
const parseParams = route.options?.params?.parse ?? route.options?.parseParams
210+
const parseParams =
211+
route.options?.params?.parse ?? route.options?.parseParams
211212
while (cursor < length) {
212213
const segment = parseSegment(path, cursor, data)
213214
let nextNode: AnySegmentNode<TRouteLike>

‎packages/router-core/tests/match-params.test.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ const root = (children: Array<TestRoute>): TestRoute => ({
2525
children,
2626
})
2727

28-
const parseWhen = (
29-
predicate: (params: Record<string, string>) => boolean,
30-
) => {
31-
return (params: Record<string, string>) => (predicate(params) ? params : false)
28+
const parseWhen = (predicate: (params: Record<string, string>) => boolean) => {
29+
return (params: Record<string, string>) =>
30+
predicate(params) ? params : false
3231
}
3332

34-
const integerParse = (key: string) => parseWhen((params) => {
35-
const value = Number(params[key])
36-
return Number.isInteger(value)
37-
})
33+
const integerParse = (key: string) =>
34+
parseWhen((params) => {
35+
const value = Number(params[key])
36+
return Number.isInteger(value)
37+
})
3838

3939
describe('params.parse route selection', () => {
4040
describe('basic matching', () => {
@@ -543,7 +543,9 @@ describe('params.parse route selection', () => {
543543
path: '{-$lang}/home',
544544
options: {
545545
params: {
546-
parse: parseWhen(({ lang }) => !lang || validLangs.includes(lang)),
546+
parse: parseWhen(
547+
({ lang }) => !lang || validLangs.includes(lang),
548+
),
547549
},
548550
},
549551
},
@@ -574,7 +576,9 @@ describe('params.parse route selection', () => {
574576
path: '{-$lang}',
575577
options: {
576578
params: {
577-
parse: parseWhen(({ lang }) => !lang || validLangs.includes(lang)),
579+
parse: parseWhen(
580+
({ lang }) => !lang || validLangs.includes(lang),
581+
),
578582
},
579583
},
580584
},

‎packages/start-plugin-core/src/start-compiler/handleCreateServerFn.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,7 @@ export function handleCreateServerFn(
436436
}
437437

438438
// Notify about discovered functions (only for non-provider files)
439-
if (
440-
!isProviderFile &&
441-
hasKeys(serverFnsById) &&
442-
context.onServerFnsById
443-
) {
439+
if (!isProviderFile && hasKeys(serverFnsById) && context.onServerFnsById) {
444440
context.onServerFnsById(serverFnsById)
445441
}
446442

0 commit comments

Comments
 (0)