0.0.11 • Published 5 years ago

vue-router-guards v0.0.11

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
5 years ago

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
  1. Guards executes in order
  2. On first failure subsequent guards will not be executed
0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.3

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

1.0.0

7 years ago