npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nuxt3-use-route-query

v1.0.2

Published

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

Readme

nuxt3-use-route-query

A Vue 3 composable to get and set URL query parameters reactively with support for different data types like string, boolean, Array, number, and ....

Installation

You can install the package via npm:

npm install nuxt3-use-route-query

Usage

Importing the Plugin

After installation, you can use the plugin by importing useRouteQuery in your Vue components. You do not need to manually install the plugin; just import and use it.

import { useRouteQuery } from 'nuxt3-use-route-query';

Example: Using useRouteQuery

Here's an example of how to use the useRouteQuery composable inside a Vue component to manage URL query parameters reactively. In a Vue Component:

<template>
  <div>
    <p>Current value of "myParam": {{ myParam }}</p>
    <input v-model="myParam" />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useRouteQuery } from 'nuxt3-use-route-query';

export default defineComponent({
  setup() {
    // Use useRouteQuery to bind a query parameter to a reactive value
    const myParam = useRouteQuery('myParam', 'defaultValue', {
      type: 'string',
      navigationType: 'replace',
    });

    return { myParam };
  },
});
</script>

In this example, the myParam query parameter will be bound to the reactive variable myParam. Any changes to myParam will update the URL, and changes to the URL will automatically update the reactive variable.

Parameters

The useRouteQuery composable accepts three parameters:

  1. key (string): The name of the query parameter you want to manage.
  2. initialValue (TypeQuery): The initial value of the query parameter if it’s not already set in the URL.
  3. config (UseRouteQueryConfig): Configuration options for the query parameter.
    • type (TypeQueryValues): The type of the query parameter. Can be one of 'boolean', 'number', 'string', 'Array', 'Array<number>', 'Array<string>', 'Array<object>'.
    • navigationType ('push' | 'replace'): The navigation type used to update the query parameter in the URL. Use 'push' to add a new entry to the history stack or 'replace' to replace the current history entry.

Query Types

The type field in the configuration defines how the query parameter should be processed. The following types are supported:

  • boolean: Interprets the value as a boolean (true or false).

  • number: Interprets the value as an number number.

  • string: Interprets the value as a string.

  • Array: Interprets the value as a comma-separated list of strings.

  • Array<number>: Interprets the value as a comma-separated list of numbers.

  • Array<string>: Interprets the value as a comma-separated list of strings.

  • Array<object>: Interprets the value as a comma-separated list of JSON-encoded objects.

Example of Different Types

boolean Type
const isLoggedIn = useRouteQuery('isLoggedIn', false, {
  type: 'boolean',
  navigationType: 'replace',
});
number Type
const userId = useRouteQuery('userId', 123, {
  type: 'number',
  navigationType: 'push',
});
Array Type
const tags = useRouteQuery('tags', [], {
  type: 'Array',
  navigationType: 'replace',
});
Array of Objects
const filters = useRouteQuery('filters', [], {
  type: 'Array<object>',
  navigationType: 'push',
});

Handling Changes

You can also watch and modify the query parameter reactively. Any change to the queryValue will update the URL, and vice versa.

For example:

const queryValue = useRouteQuery('filters', undefined);
watch(queryValue, (newValue) => {
  console.log('Query value changed:', newValue);
});

Multi Watch

const queryValue1 = useRouteQuery('filters', undefined);
const queryValue2 = useRouteQuery('filters', undefined);
watch([queryValue1,queryValue2], () => {
  console.log('queryValue1 or queryValue2 value changed:');
});

Returns

A Ref that contains the current value of the query parameter. This value is reactive and will automatically update when the query parameter in the URL changes, and vice versa.

License

MIT License. See LICENSE for details.

Contributions

Feel free to fork and contribute to this plugin! Pull requests are welcome. Make sure to add tests for any new features or bug fixes.