Typeโsafe, reactive URL query parameters for Vue 3 with full TypeScript support
npm install vue-qs  
> Note: This library is currently in active development. APIs may change significantly between versions. Please use with caution and expect breaking changes.
๐ Documentation: https://iamsomraj.github.io/vue-qs/
๐ ไธญๆๆๆกฃ: https://iamsomraj.github.io/vue-qs/zh/
Typeโsafe, reactive URL query parameters for Vue 3. Inspired by nuqs (React) but built for the Vue Composition API.
- ๐ Bidirectional Sync: URL parameters stay in sync with your reactive state
- ๐ฏ Type Safety: Full TypeScript support with type inference
- ๐ Vue 3 Ready: Built for Vue 3 Composition API
- ๐ง Flexible: Works with or without Vue Router
- ๐ก๏ธ SSR Safe: Server-side rendering compatible
- ๐ฆ Tree Shakeable: Only import what you need
- ๐จ Customizable: Built-in codecs + custom serialization support
Keep UI state (page, filters, search text, sort, tabs) in the URL so users can:
- ๐ Refresh and keep state
- ๐ Share links with specific state
- โฌ
๏ธโก๏ธ Use browser back/forward buttons
vue-qs gives you composables that feel like normal refs/reactive objects, but they automatically stay in sync with the URL query string.
``bash`
npm install vue-qsor
pnpm add vue-qsor
bun add vue-qs
Peer Dependencies:
- vue ^3.3.0 (required)vue-router
- ^4.2.0 (optional, for router integration)
`vue
`
`vue
`
`ts
// main.ts
import { createApp } from 'vue';
import { createVueQsPlugin, createVueRouterAdapter } from 'vue-qs';
import { router } from './router';
import App from './App.vue';
const app = createApp(App);
app.use(
createVueQsPlugin({
queryAdapter: createVueRouterAdapter(router),
})
);
app.use(router);
app.mount('#app');
`
`vue`
Import readyโmade codecs for common types:
`ts
import {
stringCodec,
numberCodec,
booleanCodec,
dateISOCodec,
createArrayCodec,
createJsonCodec,
} from 'vue-qs';
// Basic types
const name = queryRef('name', {
defaultValue: '',
codec: stringCodec,
});
const page = queryRef('page', {
defaultValue: 1,
codec: numberCodec,
});
const isActive = queryRef('active', {
defaultValue: false,
codec: booleanCodec,
});
// Complex types
const tags = queryRef('tags', {
defaultValue: [] as string[],
codec: createArrayCodec(stringCodec),
});
const filters = queryRef('filters', {
defaultValue: { category: 'all', sort: 'name' },
codec: createJsonCodec<{ category: string; sort: string }>(),
});
`
| Option | Type | Default | Description |
| ------------------- | ------------------------- | ------------- | -------------------------------------------- |
| defaultValue | T | - | Initial value if parameter is missing |codec
| | QueryCodec | stringCodec | Parser and serializer for the type |parse
| | QueryParser | - | Custom parser function (overrides codec) |serializeFunction
| | QuerySerializer | - | Custom serializer function (overrides codec) |shouldOmitDefault
| | boolean | true | Remove from URL when equal to default |isEqual
| | (a: T, b: T) => boolean | Object.is | Custom equality function |historyStrategy
| | 'replace' \| 'push' | 'replace' | Browser history update strategy |queryAdapter
| | QueryAdapter | - | Override default query adapter |
`ts`
const filters = queryRef('filters', {
defaultValue: { category: 'all', sort: 'name' },
codec: createJsonCodec<{ category: string; sort: string }>(),
isEqual: (a, b) => a.category === b.category && a.sort === b.sort,
});
vue-qs is SSR-safe. On the server, the composables use an internal cache until hydration, so you can render initial HTML safely without touching window.
Creates a reactive ref that syncs with a URL query parameter.
`ts`
function queryRef
Creates a reactive object that syncs multiple URL query parameters.
`ts`
function queryReactive
parameterSchema: TSchema,
options?: QueryReactiveOptions
): ReactiveQueryState
Creates an adapter for browser History API (default).
`ts`
function createHistoryAdapter(): QueryAdapter;
Creates an adapter for Vue Router integration.
`ts`
function createVueRouterAdapter(router: Router): QueryAdapter;
`bashClone and install
git clone https://github.com/iamsomraj/vue-qs.git
cd vue-qs
bun install
MIT License - see LICENSE for details.
- Inspired by nuqs for React
- Built with Vue 3 Composition API
- TypeScript support powered by TypeScript