Type-safe URL query parameter synchronization for Vue 3 with Zod validation
npm install @chronicstone/vue-route-query




A powerful Vue 3 composable for type-safe URL query parameter synchronization with Zod validation, automatic state management, and intelligent default handling.
- ๐ Type-safe: Full TypeScript support with Zod schema validation
- ๐ Bidirectional sync: Automatic synchronization between component state and URL
- ๐ฏ Deep object support: Handles nested objects and arrays with proper serialization
- โก Performance optimized: Batched updates with async processing
- ๐งน Smart cleanup: Automatically removes default values from URL
- ๐ Vue Router integration: Seamless integration with Vue Router
- ๐จ Flexible API: Support for single values or complex objects
- ๐ Nested path support: Deep object structures automatically transformed to dot notation
- ๐ Instance sync: Multiple instances with the same key stay synchronized
- ๐ History control: Choose between push and replace modes for router navigation
- @chronicstone/vue-route-query
- Features
- Table of Contents
- Installation
- Basic Usage
- Single Value
- Object Schema
- Object Schema with Root Key
- Nullable Schema
- API Reference
- useRouteQuery
- Parameters
- Returns
- Important Behavior Notes
- Advanced Usage
- Navigation Mode Control
- Object Schema with Root Key Prefix
- Complex Filtering System
- Sortable Table with Nullable State
- Dynamic Schema with Persistence Control
- Pagination with Type Safety
- Under the Hood
- State Management Lifecycle
- URL Transformation Rules
- Global Query Manager
- Performance Considerations
- Browser Support
- TypeScript Support
- Common Patterns
- Resetting to Defaults
- Conditional Parameters
- Synchronized Instances
- Troubleshooting
- Common Issues
- Debug Mode
- License
- Contributing
``bashnpm
npm install @chronicstone/vue-route-query zod vue-router
Basic Usage
$3
`typescript
import { useRouteQuery } from '@chronicstone/vue-route-query'
import { z } from 'zod'// Single value with key
const activeLayout = useRouteQuery({
key: 'layout',
schema: z.enum(['table', 'grid']),
default: 'table' // Won't appear in URL when value is 'table'
})
// Type: Ref<'table' | 'grid'>
`$3
`typescript
const filters = useRouteQuery({
schema: {
search: z.string(),
status: z.array(z.string()),
date: z.object({
from: z.string(),
to: z.string()
})
},
default: {
search: '',
status: [],
date: { from: '', to: '' }
}
})// Type: Ref<{ search: string; status: string[]; date: { from: string; to: string } }>
`$3
`typescript
const userSettings = useRouteQuery({
key: 'settings', // Optional for object schemas - adds root prefix to all properties
schema: {
theme: z.string(),
notifications: z.boolean()
},
default: {
theme: 'light',
notifications: true
}
})// URL: ?settings.theme=dark&settings.notifications=false
// Without key: ?theme=dark¬ifications=false
`$3
`typescript
const sort = useRouteQuery({
schema: {
key: z.string(),
dir: z.enum(['asc', 'desc'])
},
default: { key: 'id', dir: 'asc' },
nullable: true // Allows the entire object to be null
})// Type: Ref<{ key: string; dir: 'asc' | 'desc' } | null>
`API Reference
$3
The main composable for managing URL query parameters.
#### Parameters
| Parameter | Type | Required | Description |
| ---------- | ---------------------------------------- | -------------------------- | ----------------------------------------------------------------------- |
|
schema | z.ZodType \| Record | Yes | Zod schema for validation |
| default | NonNullable