vue-router-middleware-plugin

A vue.js plugin to implement a middleware pipeline between your routes.
4,012 11
Install
npm install vue-router-middleware-plugin
Latest Version:3.1.1
License:MIT
Last Updated:Oct 22, 2026
Links: GitHub  ·  npm
Maintainer: dsfx3d

Vue Router Middleware Plugin

A vue-router middleware pipeline.

npm version Build Status code cove Codacy Badge vue-router-middleware-plugin

The plugin utilizes vue-router navigation guards to implement easy to use, readable and more organized middlewares for your routes.

Installation

Install using NPM

npm i -S vue-router-middleware-plugin

Install using Yarn

yarn add vue-router-middleware-plugin

Get Started in 3 Easy Steps

  1. Register middleware plugin in your app.

    import Vue from 'vue'
    import MiddlewarePlugin from 'vue-router-middleware-plugin'
    import router from '@/path-to-router'
    
    Vue.use(MiddlewarePlugin, router)
    
  2. Create a middleware function.

    import store from '@/path-to-store'
    
    export default ({ to, from, redirect }) => {
      if (!store.getters.isLoggedIn) {
        redirect('/login')
      }
    }
    
  3. Attach middleware to a route.

    import AuthMiddleware from '@/path-to-auth-middleware'
    
    export default new VueRouter({
      routes: [
        {
          path: '/',
          meta: {
            middleware: AuthMiddleware
          },
          .
          .
        },
    

Note: You may attach multiple middlewares to a route.

  {
    path: '/login',
    meta: {
      middleware: [LoggerMiddleware, AnalyticsMiddleware]
    },
    .
    .
  },

Easy as that to get started.

:eyes: For advanced features like global middlewares and middleware context continue to Documentations.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Related Packages

vue-route-middleware

Make complex route middleware logic look easy and readable!

13,280 18
oidc-login-plugin

A configurable Vue 3 plugin that adds router guards, axios interceptors, and pin...

1,516
@composy/engine-vue

Vue 3 adapter for LDesign Engine

0
vue-route-handler

Elegant, fluent route definitions for Vue Router, inspired by Laravel.

1,373 4
@21cnfe/onekit-mp-cli

小程序框架开发工具

1,063

Version History

Version Released License
3.1.1 MIT
3.1.0 MIT
3.0.0 MIT
2.0.0 MIT
1.2.3 MIT
Pre-releases (2)
Version Released License
0.1.0-beta.1 MIT
0.1.0-beta.0 MIT