vue-router-guards
v0.0.11
Published
package for simplify working with guard in vue router
Downloads
3
Maintainers
Readme
Vue router guards
package for simplify working with guard in vue router
- Install
npm i -S vue-router-guards
- Initialize pipeline
import { Pipeline } from "vue-router-guards";
const pipeline = new Pipeline();
- Guard example
import { GuardResult } from "vue-router-guards";
class AuthGuard {
execute(to, from) {
if(user.isAuth()) {
return new GuardResult(true);
}
return new GuardResult(false, "/login");
}
}
- Use guard
pipeline.use(new AuthGuard());
- Pass execute method of pipeline in router hook
router.beforeEach((to, from, next) => pipeline.execute(to, from, next));
or
router.beforeEach(pipeline.execute.bind(pipeline));
- Nuances
- Guards executes in order
- On first failure subsequent guards will not be executed