1.0.7 • Published 4 years ago

vue-road v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

vue-road

it's a plugin of Vue-router that will allow you to handle middlewares

vue-router Build Status minified gzip npm license npm

vue-road is a dependency-free, lightweight plugin Vue-router that can be overwritten by yourself.

How to use?

npm install vue-road

Example

1/ First create an instance of the road bypassing callback function, inside of callback ,call the route method, route method accepts two parameters, an array of the routes as a first parameter and middlewares as a second parameter

/route
import road from "vue-road";

export default new road(function () {

    this.route([
        { path: '*', redirect: '/' },
        { path: '/404', component: () => import('./views/error/404.vue') }
    ], "init")
    
    this.route([
        { path: '/admin', component: () => import('./views/dashboard.vue')}
    ], ["auth"])
    
    this.route([
        { path: '/mail', component: () => import('./views/mail.vue') }
    ], 
    #order is important
    "auth,mail" #or ["auth","mail"]
    )
},
#You can update routes as you want them to be provided
callback(routes){ })

2/ Assign all routes of your app in Vue router constructor by calling constant method then Call middleware method bypassing an object contains Vue Router instance as router and object of middlewares

/router

import Vue from "vue";
import Router from "vue-router";
import route from "./route"
Vue.use(Router);

const opts = {
  routes: route.get(),
}
const router=new Router(opts);

route.middleware({ router, 
auth:{
    before: function ({to,from}) {
        return new Promise((resolve, reject) => {
            if(isAuth)resolve()
            reject("403")
        })
    }
}
})

export default router 

road class

apiDescriptionparameterreturn
constantreturn routes (before treatments) by middlewares passed as the second param if the first param is false it only return routes.Boolean,Array,StringArray
getreturn routes (after treatments) by middlewares passed as the second param if the first param is false it only return routes.Boolean,Array,StringArray
getMiddlewaresreturn all used middlewaresArray

License

This project is licensed under MIT License

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago