2.2.8 • Published 5 months ago

vue-router-automation v2.2.8

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

安装本项目

npm i vue-router-automation

参数说明

序号内容
参数1第一个参数是根路由指向文件
参数2第二个参数是路由meta默认自定义信息,默认为{}

使用本项目

// 在router/index.js文件使用,将包导入router/index.js文件中
const R=require('vue-router-automation');
const routers=R.Sroutes('views/index',{});//举例

// 注意:当需要添加自定义meta信息时,第二个meta参数,必须填写默认信息,不能为{}。
const routers=R.Sroutes('views/index',{header:true,footer:true});//举例

// 导出生成的路由,将生成的路由添加到vue-router中
const routes = R.routes;
const router = new VueRouter({
  routes
})
//路由自定义定制化的两种方法
//1、通过router.addRoute([路由配置对象]),如需添加多个路由,则进行循环遍历添加
const about = {    //接口返回路由信息
  path: '/about',
  name: 'About',
  meat:{
    header:false,
    footer:true
  }
  component: () => import('./views/About.vue')
};
router.addRoute(about); //添加到路由


//2、通过路由守卫进行路由定制化,自定义meta等信息

router.beforeEach((to,form,next)=>{
    //当前路由
    const Rpath=to.path;
    //定制化路由集合
    let Rarry=[
        "/",
        "/curriculum/view",
        "/news/view"
    ];
    //添加路由自定义信息
    Rarry.forEach(item=>{
        if (Rpath==item) {
          to.meta.haeder=false;
          to.meta.footer=true
        }
    })
    console.log('打印守卫信息',to)
    next();
})
2.2.5

5 months ago

2.2.7

5 months ago

2.2.6

5 months ago

2.2.8

5 months ago

2.2.1

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.4

12 months ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago