Overview
ThecreateSerializer function creates a type-safe serializer for generating URLs with search parameters. It’s useful for creating links, redirects, and programmatic navigation with properly formatted query strings.
Basic Usage
Function Signature
Parameters
ParserMap
required
An object mapping search param keys to their parser configurations.
CreateSerializerOptions
Optional configuration object.
Serialize Function
The returned serializer function has two overloads:Generate Query String
Append to Base URL
Null Values
Passingnull for a value removes it from the URL:
Usage with Link Components
Next.js
Remix
React Router
Programmatic Navigation
Server-Side Redirects (Next.js)
API Routes
Default Value Behavior
By default, values matching their parser’s default are omitted from the URL:clearOnDefault: false:
URL Keys Mapping
Map internal keys to different URL parameter names:Complex Serialization Example
Sharing with Hooks and Cache
Share the same parser configuration across serializers, loaders, caches, and hooks:Type Inference
The serializer is fully type-safe:Post-Processing
UseprocessUrlSearchParams to add custom logic:
Best Practices
1
Share parser configurations
Define parsers once and reuse them in serializers, loaders, caches, and hooks for consistency.
2
Use URL keys for clean URLs
Map verbose internal names to short URL parameter names:
3
Leverage clearOnDefault
Keep URLs clean by omitting default values (enabled by default).
4
Use null to remove parameters
Explicitly remove parameters by passing
null as their value.Related
Loaders
Parse search params with createLoader
Cache
Access params in server components
Parsers
Learn about available parser types