Provides the ability to specify multiple guards for vue router routes.
npm install vue-router-multiguard
- Guards are executed serially in the order they are supplied, respecting asynchronous ones.
- Guard execution will stop when all passed guards are executed OR when any guard calls
next()
with an argument other thanundefined
. - When a guard calls
next()
with an argument other thanundefined
, that argument will be passed to VueRouter.
multiguard(function[] guards)
-> function(to, from, next) {... }
import VueRouter from 'vue-router';
import multiguard from 'vue-router-multiguard';
const guard1 = function(to, from, next) {
setTimeout(function() {
console.log('guard1 called');
next();
}, 1000);
}
const guard2 = function(to, from, next) {
setTimeout(function() {
console.log('guard2 called');
next();
}, 1000);
}
const router = new VueRouter({
routes: [
{
name: 'home',
path: '/',
component: {},
beforeEnter: multiguard([guard1, guard2]),
}
]
});
npm test
This project is licensed under the MIT License - see the LICENSE file for details