Automatically Bind Vue-router Query to vm Instance

Automatically Bind Vue-router Query to vm Instance

vue-route-props Automatically bind vue-router query to vm, APIs are mostly same as the Vue props.


Automatically bind vue-router query to vm, APIs are mostly same as the Vue props.


npm install vue-route-props
yarn add vue-route-props


In order to make route stateful(e.g, let user to copy one route, and paste in another tab), in this way you need to pass query instead of params. vue-route-props is implemented it which is much of the same in vue props.


Edit vue-route-props

import Vue from "vue";
import VueRouter from "vue-router";
import * as VueRouteProps from "vue-route-props";


new Vue({
  routeProps: {
    optional: {
      type: String,
      default: "an optional routeProp with default value",
    required: {
      required: true,
      type: String,
    multiple: {
      type: [String, Array, Object],
    validator: {
      validator(value) {
        return value === "with custom validator";



Prop Types

In order to keep values' type, you need to ALWAYS use JSON.stringify to insert query:

  query: {
    willBeString: 0, // wrong, there will be an error occurs
    willBeNumber: JSON.stringify(0), // expected, the willBeNumber is bind with 0 now


Inspect mode

Since we bind routeProps to vm's root instead of data/computed, and so on, You cannot use the vue-dev-tools to inspect what value it is.

In order to inspect routeProps, you can enable inspect mode. we will log all routeProps when it is updated.

Vue.use(VueRouteProps, {
  inspect: true,
new Vue({
  routeProps: {
    prop: {
      type: String,
      default: "a default value",


[VueRouteProps info]: {
  prop: "a default value"

Debug mode

In general, we log errors while environment is not in production mode. you can override it with debug mode.

Vue.use(VueRouteProps, {
  debug: true,

Download Details:

Author: iendeavor


Source Code:

vue vuejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native is a framework to build cross platform native mobile apps using JavaScript. It is a wrapper around the APIs of React Native. So, with Vue Native, you can do everything that you can do with React Native. With Vue Native, you get

How to Make a Simple Vue Custom Select Component

In this article, you’ll learn how to build a Vue custom select component that can be easily be styled using your own CSS. In fact, it’s the same component that we use in production on Qvault, and you can see it in action on the playground.

Creating a Custom Tooltip Component in Vue

There are plenty of libraries out there that will have you up and running with a good tooltip solution in minutes. However, if you are like me, you are sick and tired of giant dependency trees that have the distinct possibility of breaking at any time.

Vue ShortKey plugin for Vue.js

Vue-ShortKey - The ultimate shortcut plugin to improve the UX .Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.