Skip to content
JoaoPedroAS51Public

About

Type-safe query state for Vue.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

vuqs

Type-safe query state for Vue.

npm version CI bundle size License: MIT

Keep search, filters, sort, and pagination in the URL. vuqs binds each query param to a typed, reactive ref, so there is no second copy of the state to keep in sync.

<script setup lang="ts">
import { codecs, useQueryState } from '@vuqs/core'

const search = useQueryState('q', codecs.string.withDefault(''))
const page = useQueryState('page', codecs.integer.withDefault(1))
</script>

<template>
  <input v-model="search" placeholder="Search…">
  <button @click="page++">Next page</button>
  <p>Searching “{{ search }}” on page {{ page }}</p>
</template>

Highlights

  • 🔗 Typed state in the URL. A ref bound to a query param. It writes the URL, and the URL writes it back.
  • 🧬 Not everything is a string. A codec turns ?page=2 into the number 2 and back. Built-ins cover common types, and you can define your own.
  • 🪝 It behaves like a ref. v-model, page++, whatever you'd do to a ref. Simultaneous writes end up in one navigation.
  • 🧭 Your router does the navigating. vuqs builds the next query and an adapter hands it to your router. vue-router's is included.
  • 🧩 Modules for everything else. The core does URL state. Anything on top is a module you compose with .use(), including your own.
  • 🧪 Testing and debugging. A testing adapter for asserting URL writes, and structured debug events when something looks wrong.

Documentation

📚 vuqs.dev has the full guide, module docs, and API reference.

Using Nuxt? @vuqs/nuxt adds auto-imports and installs the vue-router adapter.

Install

pnpm add @vuqs/core

Warning

vuqs is in active development. Minor releases may include breaking changes. Pin an exact version in your package.json and review the changelog before upgrading.

npm / yarn / bun
npm install @vuqs/core
yarn add @vuqs/core
bun add @vuqs/core

Requires Vue 3.5+ and Node 22+. ESM-only.

Usage

Install an adapter on the app, after the router:

// main.ts
import { installQueryAdapter } from '@vuqs/core'
import { createVueRouterAdapter } from '@vuqs/core/adapters/vue-router'
import { createApp } from 'vue'
import App from './App.vue'
import { router } from './router'

const app = createApp(App)

app.use(router)
installQueryAdapter(app, createVueRouterAdapter({ router }))

app.mount('#app')

Bind a single param with useQueryState, or a group with useQueryStates:

import { codecs, useQueryStates } from '@vuqs/core'

const { values } = useQueryStates({
  q: codecs.string.withDefault(''),
  page: codecs.integer.withDefault(1),
})

values.q = 'vue' // navigates
values.page = 2 // coalesced into the same navigation

Acknowledgements

Inspired by nuqs, which brought type-safe URL state to React. vuqs takes the idea to Vue with its own architecture.

License

MIT

About

Type-safe query state for Vue.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages