Skip to content

Commit da2bd32

Browse files
docs: Continue search param how-tos (#4814)
Add 'Validate Search Parameters with Schemas' how-to guide and update related documentation. --- [Open in Web](https://cursor.com/agents?id=bc-d5e46bba-1af4-4db9-8631-541879529bf0) • [Open in Cursor](https://cursor.com/background-agent?bcId=bc-d5e46bba-1af4-4db9-8631-541879529bf0) • [Open Docs](https://docs.cursor.com/background-agent/web-and-mobile) --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent ed49c81 commit da2bd32

File tree

6 files changed

+634
-185
lines changed

6 files changed

+634
-185
lines changed

docs/router/framework/react/how-to/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This directory contains focused, step-by-step instructions for common TanStack R
4343

4444
**Intermediate Level (Common Patterns):**
4545

46-
- [ ] Validate Search Parameters with Schemas - Use schema validation libraries for robust validation and type safety
46+
- [x] [Validate Search Parameters with Schemas](./validate-search-params.md) - Use schema validation libraries for robust validation and type safety
4747
- [ ] Handle Complex Search Parameter Types - Work with arrays, objects, dates, and nested data
4848
- [ ] Share Search Parameters Across Routes - Inherit and manage search params across route hierarchies
4949

docs/router/framework/react/how-to/drafts/validate-search-params.draft.md

Lines changed: 0 additions & 125 deletions
This file was deleted.

docs/router/framework/react/how-to/navigate-with-search-params.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,17 @@ function ConditionalNavigation() {
327327
</Link>
328328
```
329329

330+
## Common Next Steps
331+
332+
After mastering navigation with search parameters, you might want to:
333+
334+
- [Validate Search Parameters with Schemas](./validate-search-params.md) - Add robust validation with Zod, Valibot, or ArkType
335+
336+
<!-- Uncomment when guides are available
337+
- [Handle Complex Search Parameter Types](./complex-search-param-types.md) - Work with arrays, objects, dates, and nested data
338+
- [Share Search Parameters Across Routes](./share-search-params-across-routes.md) - Inherit and manage search params across route hierarchies
339+
-->
340+
330341
## Related Resources
331342

332343
- [TanStack Router Search Params Guide](https://tanstack.com/router/latest/docs/framework/react/guide/search-params) - Official documentation

docs/router/framework/react/how-to/setup-basic-search-params.md

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ function ProductsPage() {
5050
- **Error Handling**: Built-in validation error management
5151
- **Maintainability**: Clear, declarative schema definitions
5252

53-
## Validation Library Options
53+
## Validation Library Setup
5454

55-
TanStack Router supports any standard schema-compliant validation library. Choose the one that best fits your project:
56-
57-
### Zod (Most Popular)
55+
TanStack Router supports any standard schema-compliant validation library. This guide focuses on Zod for examples, but you can use any validation library:
5856

5957
```bash
6058
npm install zod @tanstack/zod-adapter
@@ -75,61 +73,9 @@ export const Route = createFileRoute('/products')({
7573
})
7674
```
7775

78-
### Valibot (Lightweight Alternative)
79-
80-
```bash
81-
npm install valibot @tanstack/valibot-adapter
82-
```
76+
**For detailed validation library comparisons and advanced validation patterns, see:** [Validate Search Parameters with Schemas](./validate-search-params.md)
8377

84-
```tsx
85-
import { valibotValidator, fallback } from '@tanstack/valibot-adapter'
86-
import * as v from 'valibot'
8778

88-
const searchSchema = v.object({
89-
page: fallback(v.number(), 1),
90-
category: fallback(v.string(), 'all'),
91-
})
92-
93-
export const Route = createFileRoute('/products')({
94-
validateSearch: valibotValidator(searchSchema),
95-
component: ProductsPage,
96-
})
97-
```
98-
99-
### Yup
100-
101-
```bash
102-
npm install yup
103-
```
104-
105-
```tsx
106-
import * as yup from 'yup'
107-
108-
const searchSchema = yup.object({
109-
page: yup.number().default(1),
110-
category: yup.string().default('all'),
111-
})
112-
113-
export const Route = createFileRoute('/products')({
114-
validateSearch: (search) => searchSchema.validateSync(search),
115-
component: ProductsPage,
116-
})
117-
```
118-
119-
### Custom Validation Function
120-
121-
For complete control, implement your own validation:
122-
123-
```tsx
124-
export const Route = createFileRoute('/products')({
125-
validateSearch: (search: Record<string, unknown>) => ({
126-
page: Number(search.page) || 1,
127-
category: (search.category as string) || 'all',
128-
showSale: Boolean(search.showSale),
129-
}),
130-
component: ProductsPage,
131-
})
132-
```
13379

13480
## Step-by-Step Setup with Zod
13581

@@ -470,8 +416,12 @@ const schema = z.object({
470416

471417
## Common Next Steps
472418

473-
<!-- Uncomment when guides are available
419+
After setting up basic search parameters, you might want to:
420+
421+
- [Validate Search Parameters with Schemas](./validate-search-params.md) - Add robust validation with Zod, Valibot, or ArkType
474422
- [Navigate with Search Parameters](./navigate-with-search-params.md) - Learn to update search params with Links and navigation
423+
424+
<!-- Uncomment when guides are available
475425
- [Handle Complex Search Parameter Types](./complex-search-param-types.md) - Work with arrays, objects, dates, and nested data
476426
-->
477427

0 commit comments

Comments
 (0)