@thiagolira/vue middlewares

Helps to manage middlewares on the Vue Router.

Version: 1.0.7 Updated: 12/20/2020

By: thiago-lira License: ISC

Downloads Last 30 Days: 26

Vue Middlewares

Just a simple package for Vue.js that allows to provide a list of middlewares.

Usage

Import to your project:

yarn add @thiagolira/vue-middlewares

And then:

import VueRouter from 'vue-router';
import vueMiddlewares from '@thiagolira/vue-middlewares';

import { myMiddleware1, myMiddleware2 } from 'path/to/middlewares';

import MyComponent from 'path/to/MyComponent.vue';

const router = new VueRouter({
  routes: [{
    path: '/login',
    name: 'login',
    component: MyComponent,
    meta: {
      middlewares: () => [myMiddleware1, myMiddleware2]
    }
  }]
})

router.beforeEach(vueMiddlewares)

Middlewares

export default {
  myMiddleware1({ to, from, next }) {
    // do something
    next()
  },
  myMiddleware2({ to, from, next }) {
    // do something
    next()
  },
}
Categories: Vue js