https://github.com/atanas-dev/vue-router-multiguard
Provides the ability to specify multiple guards for vue routes
https://github.com/atanas-dev/vue-router-multiguard
Last synced: about 1 year ago
JSON representation
Provides the ability to specify multiple guards for vue routes
- Host: GitHub
- URL: https://github.com/atanas-dev/vue-router-multiguard
- Owner: atanas-dev
- License: mit
- Created: 2017-09-09T10:55:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T21:54:18.000Z (about 6 years ago)
- Last Synced: 2025-03-27T11:37:53.103Z (about 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 88
- Watchers: 1
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Vue Router Multiguard [](https://travis-ci.org/atanas-dev/vue-router-multiguard)
Provides the ability to specify multiple guards for vue router routes.
## Installing
`npm install vue-router-multiguard`
## Notes
- 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 than `undefined`.
- When a guard calls `next()` with an argument other than `undefined`, that argument will be passed to VueRouter.
## Usage
`multiguard(function[] guards)` -> `function(to, from, next) {... }`
```js
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]),
}
]
});
```
## Running the tests
`npm test`
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details