vue-router-guards
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

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

/vue-router-guards/

    Package Sidebar

    Install

    npm i vue-router-guards

    Weekly Downloads

    1

    Version

    0.0.11

    License

    ISC

    Unpacked Size

    7.68 kB

    Total Files

    9

    Last publish

    Collaborators

    • devsinglesly